我创建了一个没有家目录的用户,现在我想为他们创建一个家目录。不仅仅是一个名为
我该怎么做?
/home/new-user
的文件夹,而是一个完整的默认家目录,包括所有正常的文件夹、隐藏文件等。我该怎么做?
/home/new-user
的文件夹,而是一个完整的默认家目录,包括所有正常的文件夹、隐藏文件等。mkhomedir_helper username
/home/username
不能存在。ls -l /home
命令检查目录的权限。我发现新目录可以被其他所有用户读取,所以我用chmod go-r-x /home/username
命令移除了这些权限。 - Don Kirkby.bashrc
。对我没有起作用。 - Desikroot
或 sudo
运行,似乎可以正常工作。 - Jesse Nicklesls -a
。也许,文件在那里,但是简单的 ls
没有显示出来。我也有同样的印象(它没有工作),因为当我执行时 /home/
是以只读方式挂载的。 - imz -- Ivan Zakharyaschevsudo mkhomedir_helper username
- Harsha Laxman您可以通过检查/etc/passwd
中的条目来验证用户的主目录是否正确设置。默认情况下,您应该看到主目录设置为/home/testinguser
:
alaa@aa-lu:~$ grep testinguser /etc/passwd testinguser:x:1001:1001::/home/testinguser:/bin/sh
如果您在那里没有看到主目录/home/testinguser
,则需要执行命令sudo usermod -d /home/testinguser testinguser
来更新它,尽管您不应该需要使用此命令,因为它应该被默认设置(根据useradd
的手册页)。
然后,我注销了我的帐户,并使用testinguser
重新登录,这是自动创建的子目录:
useradd
命令时,新用户的默认主目录并不会自动设置为/home/username
。因此,在开始之前,您必须确保这一点。 - Radu Rădeanuuseradd
的手册中可以看到:"useradd将使用在/etc/default/useradd
中指定的基本目录,或者默认情况下使用/home
。" /etc/default/useradd
中的HOME变量默认未定义,因此useradd将始终使用/home
。无论如何,我会编辑我的答案并将检查/etc/passwd
的部分提前。 - Alaa Ali/etc/passwd
中没有/bin/sh
,您需要为该用户添加一个shell,例如使用usermod -s /bin/sh testuser
命令来设置默认shell。 - rubo77useradd
命令,并带上-m
标志。这将复制/etc/skel
目录中的所有文件。useradd -m username
-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.
By default, if this option is not specified and CREATE_HOME is not enabled, no
home directories are created.
CONFIGURATION
The following configuration variables in /etc/login.defs change the behavior
of this tool:
CREATE_HOME (boolean)
Indicate if a home directory should be created by default for new users.
-m
标志,但它没有起作用;它只是复制骨架文件。 - Alaa Ali/etc/skel
不会在主目录中创建子目录。而且,useradd -m
是用于创建新用户时使用的,而不是已经添加了用户时使用的。 - Alaa Ali如果你使用adduser
命令创建了新用户,你不需要为新用户创建一个主目录。在/home
目录下会自动创建以用户名命名的主目录,其中包含以下子目录:桌面、下载、文档、音乐、图片、视频(和其他一些),供新用户使用。
如果你使用useradd
命令创建了新用户,则在终端中运行以下命令:
sudo -i #enter your user password when you are asked
gedit /etc/passwd
new_username:x:1001:1001::/home/new_username:/bin/sh
在这一行,您还可以为新用户添加真实姓名或设置默认的 shell。就像这样:
new_username:x:1001:1001:Real New Username,,,:/home/new_username:/bin/bash
小心,不要做任何其他更改。
在保存文件之后,在退出根帐户之前,请运行以下命令:
mkdir /home/new_username #to create the directory /home/new_username
cp -r /etc/skel/. /home/new_username #to copy skeleton files to /home/new_username
chown -R new_username:new_username /home/new_username #to change the owner of /home/new_username to the new user
/etc/passwd
中的条目(如果还没有)。一旦用户登录,家目录将自动填充这些子目录。然而,如果使用adduser
而不是useradd
来添加用户,所有这些都会被处理好。 - Alaa Aliadduser
命令:家目录是自动创建的。而且,在首次登录后,家目录会自动填充。 - Radu Rădeanucp /etc/skel/* /home/new_username
?另外,为什么要使用连续两个 chown
命令呢? - Alaa Alicd /home
cd mkdir username
chown username username
chgrp username username
drwxr-xr-x 16 fotanus fotanus 4096 Jun 4 17:46 .
drwxr-xr-x 9 root root 4096 Jun 4 17:43 ..
drwx------ 11 fotanus fotanus 4096 Jun 4 17:46 .cache
drwx------ 13 fotanus fotanus 4096 Jun 4 17:46 .config
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Desktop
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Documents
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Downloads
drwx------ 3 fotanus fotanus 4096 Jun 4 17:46 .gconf
drwxrwxr-x 2 fotanus fotanus 4096 Jun 4 17:46 .gstreamer-0.10
-rw------- 1 fotanus fotanus 334 Jun 4 17:45 .ICEauthority
drwxr-xr-x 3 fotanus fotanus 4096 Jun 4 17:45 .local
drwx------ 4 fotanus fotanus 4096 Jun 4 17:45 .mozilla
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Music
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Pictures
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Public
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Templates
drwxr-xr-x 2 fotanus fotanus 4096 Jun 4 17:45 Videos
-rw------- 1 fotanus fotanus 55 Jun 4 17:45 .Xauthority
-rw------- 1 fotanus fotanus 711 Jun 4 17:45 .xsession-errors
su 新用户
:D - Radu Rădeanusudo -i -u new_user
,但都不起作用。我觉得我们需要"模拟一个X登录"...不知道怎么做。 - Alaa Ali