Ubuntu Server is like any Linux variety, and has full multi-user capabilities, and a common task on any server is adding users.
就像任何Linux变种一样,Ubuntu Server具有完整的多用户功能,任何服务器上的常见任务都是添加用户。
useradd
用户添加
The useradd command will let you add a new user easily from the command line:
通过useradd命令,您可以从命令行轻松添加新用户:
useradd <username>
useradd <用户名>
This command adds the user, but without any extra options your user won’t have a password or a home directory.
该命令将添加用户,但是没有任何其他选项,您的用户将没有密码或主目录。
Note: if you get a message saying that the command is not found, try using the full path, like this:
注意:如果收到一条消息,指出未找到该命令,请尝试使用完整路径,如下所示:
/usr/sbin/useradd <username>
/ usr / sbin / useradd <用户名>
You can use the -d option to set the home directory for the user. The -m option will force useradd to create the home directory. We’ll try creating a user account with those options, and then use the passwd command to set the password for the account. You can alternatively set a password using -p on the useradd command, but I prefer to set the password using passwd.
您可以使用-d选项设置用户的主目录。 -m选项将强制useradd创建主目录。 我们将尝试使用这些选项创建一个用户帐户,然后使用passwd命令设置该帐户的密码。 您也可以在useradd命令上使用-p设置密码,但是我更喜欢使用passwd设置密码。
sudo useradd -d /home/testuser -m testuser
sudo useradd -d / home / testuser -m testuser
sudo passwd testuser
sudo passwd testuser
This will create the user named testuser and give them their own home directory in /home/testuser. The files in the new home directory are copied from the /etc/skel folder, which contains default home directory files. If you wanted to set default values for your users, you would do so by modifying or adding files in that directory. If we take a look at the new home directory for the user:
这将创建名为testuser的用户,并在/ home / testuser中为他们提供自己的主目录。 新主目录中的文件是从/ etc / skel文件夹复制的,该文件夹包含默认主目录文件。 如果要为用户设置默认值,可以通过在该目录中修改或添加文件来实现。 如果我们查看用户的新主目录:
geek@ubuntuServ:/etc/skel$ ls -la /home/testuser total 20 drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34 . drwxr-xr-x 5 root root 4096 2006-12-15 11:37 .. -rw-r–r– 1 testuser testuser 220 2006-12-15 11:34 .bash_logout -rw-r–r– 1 testuser testuser 414 2006-12-15 11:34 .bash_profile -rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc
geek @ ubuntuServ:/ etc / skel $ ls -la / home / testuser总计20 drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34。 drwxr-xr-x 5根root 4096 2006-12-15 11:37 .. -rw-r–r– 1测试用户testuser 220 2006-12-15 11:34 .bash_logout -rw-r–r– 1测试用户testuser 414 2006-12-15 11:34 .bash_profile -rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc
You’ll notice that there are bash scripts in this directory. If you wanted to set default path options for all new users, you would do so by modifying the files in /etc/skel, which would then be used to create these files by the useradd command.
您会注意到该目录中有bash脚本。 如果要为所有新用户设置默认路径选项,则可以通过修改/ etc / skel中的文件来完成,然后通过useradd命令将其用于创建这些文件。
adduser
添加用户
The adduser command is even easier than the useradd command, because it prompts you for each piece of information. I find it slightly funny that there are two virtually identically named commands that do the same thing, but that’s linux for you. Here’s the syntax:
adduser命令甚至比useradd命令更容易,因为它会提示您输入每条信息。 我发现有两个几乎完全相同名称的命令可以执行相同的操作,这有点可笑,但这是适合您的linux。 语法如下:
adduser <username>
adduser <用户名>
Example:
例:
geek@ubuntuServ:/etc/skel$ sudo adduser thegeek Password: Adding user `thegeek’… Adding new group `thegeek’ (1004). Adding new user `thegeek’ (1004) with group `thegeek’. Creating home directory `/home/thegeek’. Copying files from `/etc/skel’ Enter new UNIX password: Retype new UNIX password: No password supplied Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for thegeek Enter the new value, or press ENTER for the default Full Name []: The Geek Room Number []: 0 Work Phone []: 555-1212 Home Phone []: 555-1212 Other []: Is the information correct? [y/N] y
geek @ ubuntuServ:/ etc / skel $ sudo adduser thegeek密码:添加用户“ thegeek”…添加新组“ thegeek”(1004)。 将新用户“ thegeek”(1004)添加到“ thegeek”组。 创建主目录`/ home / thegeek'。 从`/ etc / skel'复制文件输入新的UNIX密码:重新输入新的UNIX密码:未提供密码输入新的UNIX密码:再次输入新的UNIX密码:passwd:密码已成功更新更改geek的用户信息输入新值,或按输入默认的全名[]:极客房间号[]:0工作电话[]:555-1212家庭电话[]:555-1212其他[]:信息正确吗? [y / N] y
翻译自: https://www.howtogeek.com/howto/ubuntu/add-a-user-on-ubuntu-server/