How to Create a Non-login User in Linux
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 hasrestricted access to the Linux systemand 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:
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:
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:OptionsDescription–disabled-loginIf used, the user won’t be able to use the account until the password is set.–gid IDWhen 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.–debugShows 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:
Once the new user is created, you can now set permissions for various processes and tasks. You can learn howLinux file permissions workusing 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 onhow 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:
For example, we use the command below to create a non-login user named “new_user” on our Linux system:
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
Beebom Staff
Bringing the latest in technology, gaming, and entertainment is our superhero team of staff writers. They have a keen eye for latest stories, happenings, and even memes for tech enthusiasts.
Add new comment
Name
Email ID
Δ
01
02
03
04
05