Create a new user
To add a new user in Ubuntu, you must make sure that you are part of sudo group. If yes then follow below steps.
Assuming that the new user is ‘newuser'( replace it with your desired username), run the command stated below. This command will create a user and will also set up a home directory for the user. After that, the system will prompt you to enter a password. Here you should enter a password for the ‘newuser’. Now, the system will ask you to enter user details like name and other things but you can skip them if you like. Now, Press ‘Y’ to confirm the new user.
geek@latestandhot: ~$ sudo adduser newuser [sudo] password for geek: Adding user `newuser' ... Adding new group `newuser' (1001) ... Adding new user `newuser' (1001) with group `newuser' ... Creating home directory `/home/newuser' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for newuser Enter the new value, or press ENTER for the default Full Name : New Geek #Optional, press [Enter] if you don't want Room Number : Work Phone : Home Phone : Other : Is the information correct? [Y/n] Y geek@latestandhot: ~$
Add new user to sudoers
To add newly added user to sudo group, user usermod command. If you are not logged in as root, the system might ask you for the password. Enter the password and continue
geek@latestandhot: ~$ sudo usermod -G sudo newuser Password:
All the users in sudo group have sudo privilege. Now, we can test the use privilege assigned to user by executing a command that requires sudo privilege. To test, switch to newuser account by switch user (su) command.
geek@latestandhot: ~$ sudo su - newuser Password: newuser@latestandhot: ~$
Now execute the Reboot command which requires sudo privilege. You will be prompted for the password, enter the password of newuser account.
newuser@latestandhot: ~$ sudo reboot Password: