Table of Contents
In Linux, different users have their own accounts. So, for a user, we need to create his/her account to give him/her access to Linux system. If you are a Linux administrator, you will do linux user add job too much. So, how can we ass a user in Linux? To add a new user in Linux, we will use linux useradd command with user’s name. Let ‘s add user arwen and learn how to add a user in Linux.
After adding user Arwen, let’s check it in all user list. Here, we will use tail command with -5 option to show last five users.
As you can see above, arwen is added to the users.
You can check also Linux Cheat Sheet for more Linux commands.
To delete a user, we will use linux userdel command with the name of the user. Let’s delete user arwen with userdel command.
After this command, there is no user arwen on the system. We can check /etc/passwd file which stores all the users on the system.
You can also watch the video of this lesson below!
We can also add a user with a group in Linux. By default, user is created with a group with the same name. To do this, we will use linux useradd command again but this time, we will use -G option with group name and username.
Again, to check our new user on the /etc/passwd file, we will use the tail command.
As you can see, our user has two groups. Primary one is the default group arwen and the secondary one is group ipciscoLinux.
We can also add a password to Linux user. To do this we will use linux passwd command. After entering this command, you will type user’s password twice to set her password.
To use this password and enter with user arwen, we will use su command with username Arwen. Then we will enter the password that we have set.
When we checked with whoami, as you can see I am logged in as arwen.
There are various ways to list Linux users. One of them is using cat, less or tail command with /etc/passwd file. Because all the users stored in this file.
Or we can list only last 5 users with tail -5/etc/passwd command.
Or, if you want to list only user names, you can use compgen -u command.
Again, we can use tail with compgen command to shorten out list. Belwo, we will list latest 5 users.
In this lesson, we have learned how to add a user in Linux basically with linux useradd command. We have also learned how to remove a user, how to add a user with a secondary group with one command. We saw setting user password in Linux and how to list users.
Linux user commands are very important and linux administrators use these commands too much on the job. So, to be more familiar for linux user adding, user deleting, you can practice by yourself.
Would You Like To Test Yourself With Linux Questions?
Leave a Reply