DEV Community

Artur Serra
Artur Serra

Posted on • Updated on

Write-up: KodeKloud Sysadmin (Create a Non-interactive Shell)

In this task, proposed here, the sysadmin has to create a new user with a non-interactive shell. The full prompt goes as follows:

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 mark with a non-interactive shell in the app02 server

To do so, we need to understand two commands in the Linux lexicon: ssh and adduser.

First, let's use the ssh command to log into the server specified in the prompt. You can use either

ssh -l user server
or
ssh user@server

(Remember to replace user to your actual ssh username and server to your actual ssh servername).

Once we log into the specified server, we are able to create a new user with a non-interactive shell, as prompted before. In this case, we'll need to use a flag from the adduser command, the -s. According to the adduser's manual page, the -s means:

--shell SHELL
Use SHELL as the user's login shell, rather than the default specified by the configuration file.

As it says, it will set the newly created user to a shell. We need to create a non-interactive shell, which means that we need to set the user shell to /sbin/nologin. When we do so, it will prevent the user to login. It's literally written in the nologin manual page the following:

nologin - politely refuse a login

The full command we need to run is a combination of:

sudo - To access admin privileges
adduser - The command to create a new user
user - Replace it with the new user's username.
-s - The flag to set a shell to the newly created user
/bin/nologin/ - The directory related to the nologin shell.

sudo adduser user -s /bin/nologin

Top comments (0)