While installing Ubuntu, we add a primary user account on the server; if you are using the cloud image, it comes preinstalled with the default user. This single user is enough to get all tasks done in Ubuntu. There are times when you need to create more restrictive user accounts. This recipe shows how to add a new user to the Ubuntu server.
Follow these steps to create the new user account:
$ sudo adduser bob
sudo
privileges:Y
to confirm that information is correct:/etc/passwd
:In Linux systems, the adduser
command is higher level command to quickly add a new user to the system. Since adduser
requires root privileges, we need to use sudo
along with the command, adduser
completes following operations:
If you want to skip the password prompt and finger information while adding the new user, use the following command:
$ sudo adduser --disabled-password --gecos "" username
Alternatively, you can use the useradd
command as follows:
$ sudo useradd -s <SHELL> -m -d <HomeDir> -g <Group> UserName
Where:
-s
specifies default login shell for the user-d
sets the home
directory for the user-m
creates a home
directory if one does not already exist-g
specifies the default group name for the userCreating a user with the command useradd
does not set password for the user account. You can set or change the user password with the following command:
$sudo passwd bob
This will change the password for the user account bob
.
With adduser
, you can do five different tasks:
--group
option and without the--system
option--system
optionCheck out the manual page man adduser
to get more details.
You can also configure various default settings for the adduser
command. A configuration file /etc/adduser.conf
can be used to set the default values to be used by the adduser
, addgroup
, and deluser
commands. A key value pair of configuration can set various default values, including the home
directory location, directory structure skel
to be used, default groups for new users, and so on. Check the manual page for more details on adduser.conf
with following command:
$ man adduser.conf
useradd
, a low level command to add new user to systemusermod
, a command to modify a user account