Create a Linux User with non-interactive shell

Create a Linux User with non-interactive shell – Kodekloud Engineer

Task details: The System admin team of xFusionCorp Industries has installed a backup agent tool on all app servers. As per the tool’s requirements, they need to create a user with a non-interactive shell.

Therefore, create a user named john with a non-interactive shell on the App Server 3

In this article, we’ll discuss a way to create a new user with a non-interactive shell using the useradd command.

For creating a non-interactive user, we’ll use /sbin/nologin — is specifically designed to switch a shell and produces output complaining you cannot log in.

Follow the steps below to create a Linux user with non-interactive shell:

Step 1: At first login to the respective mentioned server in the task from the Jump host. For me, it’s app server 3.

$ ssh banner@172.16.238.12

Enter the password to complete the authentication.

Step 2: Substitue user context to root user

$ sudo su -

Enter the password to complete the authentication for the root user.

Step 3: First check if the user already exists on the server with the below command

# id john

Step 4: If the user is not found then you create a new user with a non-interactive shell. 

# useradd john  -s /sbin/nologin

Step 5:  Validate if the user is created successfully as per the task requirement.

# id john

or
 
# cat /etc/passwd | grep john

Step 6: Click on Finish & Confirm to complete the task successfully.

Happy learning!!

Check out Linux File Permissions

Leave a Comment