If you are a system administrator and are looking for ways to make your Linux system more secure or want to automate certain processes, creating a non-login user is the solution. Non-login users can prove to be very useful for a variety of cases right from limiting access to your Linux system to running specific processes with restricted privileges. Here, we will guide you through the steps to create a non-login user in Linux and set the appropriate permissions for them.
What Is a Non-login User in Linux?
A non-login user is a type of user account that has restricted access to the Linux system and can only perform specific tasks or run certain processes without logging into the system. Unlike regular users, non-login users do not have access to a regular shell or the home directory. Hence, they cannot log in to your Linux PC. Some common uses of creating a non-login user are to automate tasks, run specific processes or improve your system’s overall security by restricting access.
How to Create a User Without Login in Linux
There are two different methods to create a non-login user in Linux, which are straightforward and easy. But there are some prerequisites you need to take care of:
- Any Linux-based operating system (preferably the latest version)
- A user with root access or sudo privilege
Now that you have the prerequisites, we will now discuss using the adduser command and editing the passwd file to create non-login users in Linux.
1. Using the adduser Command
Thanks to its simplicity and easy-to-use syntax, we generally use the “adduser” command to create new users in Linux. The basic syntax to create a user using the adduser command is:
sudo adduser <username> --system --no-create-home
In the above syntax, the “–system” option creates a new user account without a password and without a shell. Furthermore, to prevent the command from creating a new home directory, we use the “–no-create-home” option here. Other common options you can pair with the command are:
Options Description --disabled-login
If used, the user won’t be able to use the account until the password is set. --gid ID
When creating a user, this option will put the user in that group. --home <directory_name>
Use <directory_name> as the user’s home directory, rather than the default location. --shell <shell_path>
Use <shell_path> as the user’s login shell, rather than the default shell. --debug
Shows informational messages on every operation taking place.
For example, to create a non-login user with the username “test_user” in Linux, use this command:
sudo adduser test_user --system --no-create-home
Once the new user is created, you can now set permissions for various processes and tasks. You can learn how Linux file permissions work using the linked article.
2. Editing the “/etc/passwd” File
The “/etc/passwd” file is a system file that stores information about all user accounts on a Linux system. This file has read permissions for all user types and only the superuser holds write permissions. We saw the contents of the “passwd” file in our recent article on how to list users in Linux. To create a non-login user in Linux, you can manually edit the /etc/passwd file to add a new entry for the new account with the following steps:
- Open the Terminal in your Linux system.
- Then, use the nano command in Linux to open the “/etc/passwd” file. You can use any other Linux text editor you like, but if you’re following along, then paste the following command in the Command Line:
sudo nano /etc/passwd
- Next, scroll down to the bottom of the list and add a new non-login user with this command:
<username>:x:<UID>:<GID>:<user_description>:/dev/null:/bin/false
For example, we use the command below to create a non-login user named “new_user” on our Linux system:
new_user:x:1001:1001:New Non-Login User:/dev/null:/bin/false
- Finally, save and exit the nano editor for the changes to take place. If you are using the Vim editor, follow our guide to learn how to exit the Vim editor in Linux.
- Once the new user is created, you can now adjust the permissions for it for various processes and tasks.
Note:
Always keep a backup of the “/etc/passwd” file as modifying this file is risky, and in the worst case, it can render your system useless.
There are three types of users in Linux:
1. Super User: It is a type of user with the highest level of permissions in the system; also known as the “root user”
2. Normal User: These types of users have restricted access to the commands and files along with a shell and a home directory.
3. System User: Also known as the “Non-login” user; they neither have access to a shell nor to a home directory. All they have access to is some specific commands they are allowed to run.
To view all users present in the Linux system, use this command: cat /etc/passwd