Answers:
man useradd 状态:
useradd is a low level utility for adding users. On Debian,
administrators should usually use adduser(8) instead.
注意 low level utility
要添加用户,请adduser改用。这是一个更高级的实用程序。
此外,查看-d选项:
-d, --home HOME_DIR
The new user will be created using HOME_DIR as the value for the
user's login directory. The default is to append the LOGIN name to
BASE_DIR and use that as the login directory name. The directory
HOME_DIR does not have to exist but will not be created if it is
missing.
The directory will not be created if it is missing.
一般远离useradd,adduser改为使用。
adduser但是创建的主目录仍然只包含一个文件examples.desktop,没有别的。如何获得Ubuntu创建默认文件夹Desktop,Downloads等?(我通过ssh登录)
adduser如果有人将/etc/login.defs中的CREATE_HOME更改为“ no”,则不会创建目录。您可以使用-m标志覆盖它。
与根据man useradd,-d /home/linda选项将不会创建目录/home/linda,如果没有这个。因此,您必须手动创建它。为此,请在终端中运行以下命令:
sudo -i #to get root privileges
mkdir /home/linda #to create the directory /home/linda
cp -rT /etc/skel /home/linda #to populate /home/linda with default files and folders
chown -R linda:linda /home/linda #to change the owner of /home/linda to user linda
另请参阅:创建帐户后如何制作用户主文件夹?
查看/etc/defaults/useradd是否要更改默认值。采用:
useradd -m -d /home/joe -s /bin/bash。
-m, --create-home Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory. useradd will create the home directory unless CREATE_HOME in /etc/login.defs is set to no.@astrojuanlu
使用adduser。
DESCRIPTION
adduser and addgroup add users and groups to the system according to
command line options and configuration information in
/etc/adduser.conf. They are friendlier front ends to the low level
tools like useradd, groupadd and usermod programs, by default choosing
Debian policy conformant UID and GID values, creating a home directory
with skeletal configuration, running a custom script, and other fea‐
tures. adduser and addgroup can be run in one of five modes:
useradd您必须自己添加所有选项。包括权限和其他一些东西。adduser根据合理的默认值执行此操作(并自行添加主目录)。
如果需要使用adduser,则可能需要-b选项和-d选项!
您没有创建主目录的最可能的原因是因为您没有CREATE_HOME yesin /etc/login.defs。
您可以按照@OmPS或@RaduRădeanu的建议来解决此问题。
但是,有很多方法可以通过使用以下命令之一来克服此问题:
的结果 sudo adduser linda
Adding user 'linda'
Adding new group 'linda' (1001) ...
Adding new user 'linda' (1001) with group 'linda' ...
Creating home directory '/home/linda' ...
Copying files from '/etc/skel' ...
****Password confirmation****
****Name prompt****
/etc/adduser.conf如果
--home未指定option,则从adduser中选择默认值。
请注意,它还会复制/etc/skel内容。
将adduser与 --home
sudo adduser --home /home/linda与上一个选项相同,但是如果用户的主目录与您分配的用户名不同,则可能需要此选项。
指定要useradd命令的基本目录:
sudo useradd -b /home使用login.defs:/etc/login.defs在执行以下操作之前,修改并添加以下行sudo useradd:
CREATE_HOME yes注意:如果您这样做man login.defs,目前会显示
影子密码套件以前提供的许多功能现在都由PAM处理。因此,passwd(1)不再使用/etc/login.defs,login(1)和su(1)不再使用/etc/login.defs。请参考相应的PAM配置文件。
使用pam_mkhomedir PAM模块:从man pam_mkhomedir页面开始,将以下行添加到/etc/pam.d/login:
session required pam_mkhomedir.so skel=/etc/skel