Suppose you have already installed the Ubuntu desktop or server. In that case, it means you have already created a default user on your system, even on the cloud also Ubuntu is installed with preconfigured default user account.
You can do all administrative tasks using this user, but sometimes you need to create another user for your team member or something else.
Here, In this ttorial, I’ll show you how to create a new user on Ubuntu Desktop or Server system.
Getting ready
You should have root or superuser privileges to create a new user on Ubuntu Server or Desktop.
How to do it…
Follow these steps to create the new user account:
To add a new user in Ubuntu, enter following command in your shell:
[et_pb_dmb_code_snippet code=”JCBzdWRvIGFkZHVzZXIgYm9i” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBzdWRvIGFkZHVzZXIgYm9i[/et_pb_dmb_code_snippet]
Enter your password to complete the command with sudo
privileges:
Now enter a password for the new user:
Confirm the password for the new user:
Enter the full name and other information about the new user; you can skip this part by using the Enter key.
Enter Y
to confirm that information is correct:
This should have added new user to the system. You can confirm this by viewing the file /etc/passwd
:
How it works…
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:
[et_pb_dmb_code_snippet code=”QWRkcyBhIG5ldyB1c2VyLgoKQWRkcyBhIG5ldyBkZWZhdWx0IGdyb3VwIHdpdGggdGhlIHNhbWUgbmFtZSBhcyB0aGUgdXNlci4KCkNob29zZXMgVUlEICh1c2VyIElEKSBhbmQgR0lEIChncm91cCBJRCkgY29uZm9ybWluZyB0byB0aGUgRGViaWFuIHBvbGljeS4KCkNyZWF0ZXMgYSBob21lIGRpcmVjdG9yeSB3aXRoIHNrZWxldGFsIGNvbmZpZ3VyYXRpb24gKHRlbXBsYXRlKSBmcm9tIC9ldGMvc2tlbC4KCkNyZWF0ZXMgYSBwYXNzd29yZCBmb3IgdGhlIG5ldyB1c2VyLgoKUnVucyB0aGUgdXNlciBzY3JpcHQsIGlmIGFueS4=” _builder_version=”4.9.4″ _module_preset=”1c65a322-8013-4663-a6cf-5403dbd500d3″]QWRkcyBhIG5ldyB1c2VyLgoKQWRkcyBhIG5ldyBkZWZhdWx0IGdyb3VwIHdpdGggdGhlIHNhbWUgbmFtZSBhcyB0aGUgdXNlci4KCkNob29zZXMgVUlEICh1c2VyIElEKSBhbmQgR0lEIChncm91cCBJRCkgY29uZm9ybWluZyB0byB0aGUgRGViaWFuIHBvbGljeS4KCkNyZWF0ZXMgYSBob21lIGRpcmVjdG9yeSB3aXRoIHNrZWxldGFsIGNvbmZpZ3VyYXRpb24gKHRlbXBsYXRlKSBmcm9tIC9ldGMvc2tlbC4KCkNyZWF0ZXMgYSBwYXNzd29yZCBmb3IgdGhlIG5ldyB1c2VyLgoKUnVucyB0aGUgdXNlciBzY3JpcHQsIGlmIGFueS4=[/et_pb_dmb_code_snippet]
If you want to skip the password prompt and finger information while adding the new user, use the following command:
[et_pb_dmb_code_snippet code=”JCBzdWRvIGFkZHVzZXIgLS1kaXNhYmxlZC1wYXNzd29yZCAtLWdlY29zICIiIHVzZXJuYW1l” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBzdWRvIGFkZHVzZXIgLS1kaXNhYmxlZC1wYXNzd29yZCAtLWdlY29zICIiIHVzZXJuYW1l[/et_pb_dmb_code_snippet]
Alternatively, you can use the useradd command as follows:
[et_pb_dmb_code_snippet code=”JCBzdWRvIHVzZXJhZGQgLXMgPFNIRUxMPiAtbSAtZCA8SG9tZURpcj4gLWcgPEdyb3VwPiBVc2VyTmFtZQ==” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBzdWRvIHVzZXJhZGQgLXMgPFNIRUxMPiAtbSAtZCA8SG9tZURpcj4gLWcgPEdyb3VwPiBVc2VyTmFtZQ==[/et_pb_dmb_code_snippet]
[et_pb_dmb_code_snippet code=”LXMgc3BlY2lmaWVzIGRlZmF1bHQgbG9naW4gc2hlbGwgZm9yIHRoZSB1c2VyCgotZCBzZXRzIHRoZSBob21lIGRpcmVjdG9yeSBmb3IgdGhlIHVzZXIKCi1tIGNyZWF0ZXMgYSBob21lIGRpcmVjdG9yeSBpZiBvbmUgZG9lcyBub3QgYWxyZWFkeSBleGlzdAoKLWcgc3BlY2lmaWVzIHRoZSBkZWZhdWx0IGdyb3VwIG5hbWUgZm9yIHRoZSB1c2Vy” _builder_version=”4.9.4″ _module_preset=”1c65a322-8013-4663-a6cf-5403dbd500d3″]LXMgc3BlY2lmaWVzIGRlZmF1bHQgbG9naW4gc2hlbGwgZm9yIHRoZSB1c2VyCgotZCBzZXRzIHRoZSBob21lIGRpcmVjdG9yeSBmb3IgdGhlIHVzZXIKCi1tIGNyZWF0ZXMgYSBob21lIGRpcmVjdG9yeSBpZiBvbmUgZG9lcyBub3QgYWxyZWFkeSBleGlzdAoKLWcgc3BlY2lmaWVzIHRoZSBkZWZhdWx0IGdyb3VwIG5hbWUgZm9yIHRoZSB1c2Vy[/et_pb_dmb_code_snippet]
Creating 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:
[et_pb_dmb_code_snippet code=”JCBzdWRvIHBhc3N3ZCBib2I=” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBzdWRvIHBhc3N3ZCBib2I=[/et_pb_dmb_code_snippet]
This will change the password for the user account bob
.
Note:
Note that if you skip the username part from the above command you will end up changing the password of the root account.
With adduser
, you can do five different tasks:
- Add a normal user
- Add a system user with system option
- Add user group with the
--group
option and without the --system
option
- Add a system group when called with the
--system
option
- Add an existing user to existing group when called with two non-option arguments
Check 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:
[et_pb_dmb_code_snippet code=”JCBtYW4gYWRkdXNlci5jb25m77u/” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBtYW4gYWRkdXNlci5jb25m77u/[/et_pb_dmb_code_snippet]
Creating user accounts in batch mode
In this section, you will see how to create multiple user accounts in batch mode without using any external tool.
Getting ready
You will need a user account with root or root privileges.
How to do it…
Follow these steps to create a user account in batch mode:
Create a new text file users.txt
with the following command:
[et_pb_dmb_code_snippet code=”JCB0b3VjaCB1c2Vycy50eHQ=” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCB0b3VjaCB1c2Vycy50eHQ=[/et_pb_dmb_code_snippet]
Change file permissions with the following command:
[et_pb_dmb_code_snippet code=”JCBjaG1vZCA2MDAgdXNlcnMudHh0″ _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBjaG1vZCA2MDAgdXNlcnMudHh0[/et_pb_dmb_code_snippet]
Open users.txt
with GNU nano and add user account details:
[et_pb_dmb_code_snippet code=”JCBuYW5vIHVzZXJzLnR4dA==” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f”]JCBuYW5vIHVzZXJzLnR4dA==[/et_pb_dmb_code_snippet]
Press Ctrl + O to save the changes.
Press Ctrl + X to exit GNU nano.
Enter $ sudo newusers users.txt
to import all users listed in users.txt
file.
Check /etc/passwd
to confirm that users are created:
How it works…
We created a database of user details listed in same format as the passwd file. The default format for each row is as follows:
[et_pb_dmb_code_snippet title=”/etc/passwd” code=”dXNlcm5hbWU6cGFzc3dkOnVpZDpnaWQ6ZnVsbCBuYW1lOmhvbWVfZGlyOnNoZWxs” _builder_version=”4.9.4″ _module_preset=”369a0a83-f997-4079-bcdc-749886c9e1c7″ hover_enabled=”0″ sticky_enabled=”0″]dXNlcm5hbWU6cGFzc3dkOnVpZDpnaWQ6ZnVsbCBuYW1lOmhvbWVfZGlyOnNoZWxs[/et_pb_dmb_code_snippet]
[et_pb_dmb_code_snippet code=”dXNlcm5hbWU6IFRoaXMgaXMgdGhlIGxvZ2luIG5hbWUgb2YgdGhlIHVzZ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CBhIG5ldyB1c2VyIHdpbGwgYmUgY3JlYXRlZC4KCnBhc3N3b3JkOiBUaGlzIGlzIHRoZSBwYXNzd29yZCBvZiB0aGUgdXNlci4KCnVpZDogVGhpcyBpcyB0aGUgdWlkIG9mIHRoZSB1c2VyLiBJZiBlbXB0eSwgYSBuZXcgdWlkIHdpbGwgYmUgYXNzaWduZWQgdG8gdGhpcyB1c2VyLgoKZ2lkOiBUaGlzIGlzIHRoZSBnaWQgZm9yIHRoZSBkZWZhdWx0IGdyb3VwIG9mIHVzZXIuIElmIGVtcHR5LCBhIG5ldyBncm91cCB3aWxsIGJlIGNyZWF0ZWQgd2l0aCB0aGUgc2FtZSBuYW1lIGFzIHRoZSB1c2VybmFtZS4KCmZ1bGwgbmFtZTogVGhpcyBpbmZvcm1hdGlvbiB3aWxsIGJlIGNvcGllZCB0byB0aGUgZ2Vjb3MgZmllbGQuCgpob21lX2RpcjogVGhpcyBkZWZpbmVzIHRoZSBob21lIGRpcmVjdG9yeSBvZiB0aGUgdXNlci4gSWYgZW1wdHksIGEgbmV3IGhvbWUgZGlyZWN0b3J5IHdpbGwgYmUgY3JlYXRlZCB3aXRoIG93bmVyc2hpcCBzZXQgdG8gbmV3IG9yIGV4aXN0aW5nIHVzZXIuCgpzaGVsbDogVGhpcyBpcyB0aGUgZGVmYXVsdCBsb2dpbiBzaGVsbCBmb3IgdGhlIHVzZXIu[/et_pb_dmb_code_snippet]
The new user command reads each row and updates the user information if the user already exists, or it creates a new user.
We made the users.txt
file accessible to owner only. This is to protect this file, as it contains the user’s login name and password in unencrypted format.
0 Comments