Introduction to Non-Interactive Shell in Linux
A non-interactive shell in Linux is a shell that is typically used for running automated scripts or commands that don't require user interaction. Such shells are executed without the normal environment and settings of an interactive shell, allowing the execution of commands to be done without interruption.
For example, you can use a non-interactive shell to schedule a cron job that runs a script every day at a specific time to back up the data on your server. The script is executed by the non-interactive shell, and the backups are done without any human intervention, ensuring that the backups are done at the scheduled time without fail.
Infrastructure
Signup to KodeKloud - Engineer for practicing this task hands-on.
Task Details
Create a Linux User with a non-interactive shell 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.
Perform the below commands based on your question server, user name & other details might differ. So please read the task carefully before executing it. All the Best 👍
Solution:
1. Login on the App server as per the task
Server Name | IP | Hostname | User | Password | Purpose |
stapp01 | 172.16.238.10 | stapp01.stratos.xfusioncorp.com | tony | Ir0nM@n | Nautilus App 1 |
stapp02 | 172.16.238.11 | stapp02.stratos.xfusioncorp.com | steve | Am3ric@ | Nautilus App 2 |
stapp03 | 172.16.238.12 | stapp03.stratos.xfusioncorp.com | banner | BigGr33n | Nautilus App 3 |
thor@jump_host /$ ssh steve@stapp02
The authenticity of host 'stapp02 (172.16.238.11)' can't be established.
ECDSA key fingerprint is SHA256:NgyY+fBF5b56d9UEyUmbNHqK7eZTbk5n5/Ypr19rQkk.
ECDSA key fingerprint is MD5:ef:d2:32:cb:57:6f:44:cb:0c:0b:4f:82:f0:dc:92:70.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'stapp02,172.16.238.11' (ECDSA) to the list of known hosts.
steve@stapp02's password: Am3ric@
[steve@stapp02 ~]$
[steve@stapp02 ~]$ sudo su -
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for steve:Am3ric@
[root@stapp02 ~]#
A brief Description about commands "ssh" and "sudo su-" is give in Essential Linux Commands.
2. Check user exists on the server
[root@stapp02 ~]# id ravi
id: ravi: no such user
[root@stapp02 ~]#
id
"id" command is used to display user and group information for a specified user in Linux, including the user ID (UID) and primary group ID (GID), as well as any supplementary groups that the user is a member of.
3. If the user is not found then we create a user with a Non-Interactive Shell
[root@stapp02 ~]# adduser ravi -s /sbin/nologin
[root@stapp02 ~]#
adduser
It is used for creating new user accounts on a Linux machine, with a default home directory and default group.
You need to have root or administrative privileges to be able to run this command.
4. Validate
[root@stapp02 ~]# id ravi
uid=1002(ravi) gid=1002(ravi) groups=1002(ravi)
[root@stapp02 ~]# cat /etc/passwd |grep ravi
ravi:x:1002:1002::/home/ravi:/sbin/nologin
[root@stapp02 ~]#
cat & grep
"cat /etc/passwd | grep ravi" is a command in Linux that is used to display information about a specific user, "ravi" in this case. The command is composed of two parts: "cat /etc/passwd" and "grep ravi".
The first part, "cat /etc/passwd", is used to display the contents of the file "/etc/passwd". This file contains information about all the users on the system, including their user name, user ID, and default home directory.
The second part, "grep ravi", is used to filter the contents of the file "/etc/passwd" and only display the lines that contain the string "ravi". The "grep" command is used to search for patterns in text and it will filter the content to display only the lines that match the pattern.
In summary, "cat /etc/passwd | grep ravi" is a command that is used to display information about a specific user "ravi" in the file "/etc/passwd" by displaying the contents of the file and then filtering it to show only the lines that contain the string "ravi".
Thank you so much for taking your valuable time to read
I took the initiative to learn in public and share my work with others. I tried my level best in squeezing as much information as possible in the easiest manner. Hope you learned something new today :)
Learn Essential Linux Commands
Signup to KodeKloud - Engineer for practicing these tasks hands-on.
In the next part of this blog, we will study 👇