Sunday, 5 July 2020

What is Linux shell?

26. What is Linux shell? How to check current shell?

A Linux shell is a command interpreter or a program that accepts commands and passes them to the operating system for execution. To check the shell that you are using, run # echo $0.

27. What command to find memory and swap usage?

# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         347         460           7         164         481
Swap:          2047           0        2047

28. Mention the steps to find out the memory usage by Linux?

# cat /proc/meminfo

When you will enter this command then you will see a list of memory usage like Total Memory, Free Memory, Cache memory, and many other memory usages by Linux. 

Other commands used in Linux are:

$ free –m    # this is the simplest command where it will show the memory usage in MB.
$ vmstat –s # this command gives a report on virtual memory statistics.
top              # this command checks the usage of memory and cpu usage.
htop            # similar like top command.

29. How to rename file and directory in Linux?

To rename files, use the mv command. Note that for this to work, the path of the file to be renamed needs to be the same. 

For example, to rename the file file1.doc in /data/files directory to file2.doc 
execute the command: mv /data/files/file1.doc /data/files/file2.doc

30. What is Input/output Redirection?

Directing input & outputs data to and from processes is called Input/Output Redirection. Input / Output redirection is a required feature for good programming and shell scripting. It’s used for taking input and showing results as per requirement. Input from user and passing to other process is called input redirection whereas if process further pass its output to another process or function that will be output redirection for that and input redirection for receiving one.

three redirections available as below: -

Input Redirection: ‘<’ symbol is used for input redirection to the new process.
Output Redirection: ‘>’ symbol is used for output redirection to a new process or log file.
Error Redirection: It is denoted as STDERR(2). This is very useful for error handling.

31. How to copy files and directory in Linux?

To copy files in Linux, use the cp command. The syntax is quite simple
# cp  /source/of/the/file  /destination/of/the/file

32. How to create empty file in Linux?

To create an empty file in Linux, use the touch command as shown:
touch new_file

33. Briefly define ls command and options?

This is one of the most basic and useful commands. This command (“ls”) is used by a normal user or system administrator on a regular basis. This command is used to list down files and directories in the present working directory. 

“ls” Command comes up with multiple options:-

-l This option will show file & directory permissions in rwxrwxrwx format for user, group & others
-a This option allows you to view hidden & system files
-i This option gives you inode details of files
-s Helps you to list down file size

“ls” without any options will list down all files & directories in plain text. This command gives more desired outputs after clubbing it with grep & less command that allows your filter the list or highlights the required file. This command is also compatible with input-output redirection option which is very helpful for logging.

34. What is the difference between ctrl+z and ctrl+c?

When we have a process in progress which handle your prompt, there were some signals (orders) that we can send to theses process to indicate what we need:

Control+C sends SIGINT which interrupts the application. Usually causing it to abort, but a process is able to intercept the signal and do whatever it likes: for instance, from the Bash prompt, try Ctrl-C. In Bash, it cancels whatever you've typed and gives you a blank prompt (as opposed to the quitting Bash)

Control+Z sends SIGTSTP to foreground application, effectively putting in the background on suspended mode. This is very much useful when we want the application to continue its process while we are doing another job in the current shell. When we finish the job, we can go back into the application by running FG (or %x where x is the job number as shown in jobs).

35. How to create files in Linux?

To create files, use the touch command. For example to create a file file1.doc run the command:
# touch file1.doc

Also use cat command followed by the redirection operator or greater than sign >
# cat > file1.doc
Type the file contents and hit CTRL + D

Using the vi command,
# vi file1.doc
Type the file contents and hit ESC and save :wq

36. What is a Socket?

A Socket is a form of Interprocess Communication and Synchronization that can be used to transfer data from one process to another, either on the same host computer or on different hosts connected by a network; Network sockets are identified by source IP address source port and destination IP address and port.

37. What is the difference between the tar, gz, and zip?

Tar & ZIP are two most commonly used utilities in Linux system

TAR is archiver utility which will archive the selected files or directories. Extension of TAR is .tar.

gz is known as gunzip used compress files only. Extension of gz is .gz. You can use gz on TAR to compression directories achieved by TAR.

ZIP is archiver and compression utility for files and directory. Extension of ZIP is .zip.

The benefit of TAR can be applied on directories. Sometimes, you do not want to compress the filer but want to bundle them, TAR is perfect for it. TAR with GZIP is the best combination. Like GZIP, we also have bzip2 which use a completely new algorithm to compress files has given less size in compare to gzip.

38. Briefly explain the process of sending an email?

The basic steps of this process are mentioned below for your convenience.

Step 1: After composing a message and send, your email client - whether it's Outlook Express or Gmail - connect to the domain's SMTP server. This server can name many things; a standard example would be

Step 2: In this step, the email client communicates with the SMTP server by giving your email address, the recipient's email address, the message body, and any attachments.

Step 3: Now SMTP server has complete details to processes the recipient's email address - especially its domain. If the domain name is the same as the sender's, the message is routed directly over to the domain's POP3 or IMAP server - no routing between servers needed. If the domain is different, though, the SMTP server will have to communicate with the other domain's server.

Step 4: To deliver email and to find the recipient's server, the sender's SMTP server has to communicate with the DNS or Domain Name Server. The DNS will take the recipient's email domain name and translates this into an IP address. The sender's server cannot route an email properly with a domain name alone; an IP address is a unique number that is assigned to every computer that is connected to the Internet. By knowing information, an outgoing mail server can perform its work more efficiently.

Step 5: Once SMTP server got the recipient's IP address, it can connect to its SMTP server. This isn't done directly, though; instead, the message is routed along with a series of unrelated SMTP servers until it arrives at its destination.

Step 6: The recipient's SMTP server scans the incoming message. If the domain and user name are valid, it forwards the message along to the domain's POP3 or IMAP server. From there, it is placed in a send mail queue until the recipient's email client allows it to download. At that point, the message can read by the recipient.

39. What is the difference between the mail client and the mail server?

Email client primarily is a desktop or mobile application that enables users to receive and send emails directly on the desktop or mobile. Typically, email client requires an email address to be set up, mail server details & connectivity to the mail server to configure and use email service. These configuration and settings include email address, password, POP3/IMAP and SMTP address, port number, email aliases, and other related preferences.

A mail server or an email server is a server that supports email function in network and support clients to handles and delivers e-mail over a network. This can be over intranet or internet. Email server receives emails from client computers and delivers them to other mail servers after proper authentication and authorization. Mail servers use MTA (Mail transfer agent) with SMTP (Simple Mail Transfer Protocol) to support email transmission. You have used any open source free MTA or any paid version the basis of your requirements and security policies.

40. What are network zones?

Network Zone explains the trust level of a network connection. Creating Zones helps in identifying the secure network or unsecured network. This helps Network administrators to plan the level of monitoring for different networks.

The network zone example,

Trusted:                 Fully trusted connections. All the incoming traffic is allowed.
home work internal:         Partly trusted connections. User/administrator defines open services.
DMZ:                 Mostly untrusted connections, the demilitarized zone.
Public external:         Mostly untrusted connections. User/administrator defines the open services.
Block:         Fully untrusted connections. No incoming traffic is allowed.
Drop:         Fully untrusted connections. All packets are dropped immediately.

41. How to check if a particular service in running?

To check if a service is running, use the syntax:
# systemctl status service_name

For instance, to check is Postfix is running, run the command:
# systemctl status postfix

42. How to start a service on reboot?

To start a service on reboot run use the syntax:
# systemctl enable service_name

For example, to start httpd web server upon a reboot, run
# systemctl enable httpd

43. How do you start and stop a service?

To start a service in a systemd system, run the command:
# systemctl start service_name

For example, to start ssh service, run the command:
# systemctl start sshd

To stop the service, run:
# systemctl stop service_name

To stop ssh run:
# systemctl stop sshd

44. How do you check disk usage?

Use the df command to check the space used on your hard drive and the space remaining / free space.
Additionally, use the du command to check usage by specific files and directories.

45. What is initrd image?

The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real root file system is available. The initrd is bound to the kernel and loaded as part of the kernel boot procedure. The kernel then mounts this initrd as part of the two-stage boot process to load the modules to make the real file systems available and get at the real root file system. Thus initrd image plays a vital role in linux booting process.

46. Explain the terms suid, sgid and sticky bit?

In addition to the basic file permissions in Linux, there are few special permissions that are available for executable files and directories.

SUID: If setuid bit is set, when the file is executed by a user, the process will have the same rights as the owner of the file being executed.

SGID: Same as above, but inherits group privileges of the file on execution, not user privileges. Similar way when you create a file within the directory, it will inherit the group ownership of the directories.

Sticky bit: Sticky bit was used on executables in linux so that they would remain in the memory more time after the initial execution, hoping they would be needed in the near future. But mainly it is on folders, to imply that a file or folder created inside a stickybit enabled folder could only be deleted by the owner. A very good implementation of sticky bit is /tmp , where every user has write permission but only users who own a file can delete them.

47. Which one is the default sticky bit directory?


48. Explain /proc filesystem?

/proc is a virtual file system that provides detailed information about the Linux kernel, hardware, and running processes. /prod is a generic file available in all flavors of Linux. Files under /proc directory named as Virtual files. These files are created when the system boots up and dissolve on shutdown. It contains information about running processes and works as an information zone for the kernel.

/proc is also a hidden tool for a system administrator for analyzed and troubleshooting performance and system bottleneck related issues.
These virtual files have unique qualities. Most of them are listed as zero bytes in size as they reside in memory, not on disk. Virtual files such as the /proc/interrupts, /proc/meminfo, /proc/mounts, and the /proc/partitions provide an up-to-the-moment glimpse of system’s hardware. Others: /proc/filesystems file and /proc/sys/ directories provide system configuration information and interfaces. These are tools for a system administrator to troubleshoot and analyze the issues.

49. What are the run levels in linux and how to change them?

A run level is a state of init and the whole system that defines what system services are operating and they are identified by numbers. There are 7 different run levels present (run level 0-6) in a Linux system for the different purpose. 

The descriptions are given below.

0: Halt System (To shutdown the system)
1: Single user mode
2: Basic multi user mode without NFS
3: Full multi user mode (text based)
4: unused
5: Multi user mode with Graphical User Interface
6: Reboot System

To change the run level, edit the file “/etc/inittab” and change initdefault entry ( id:5:initdefault:). If we want to change the run level on the fly, it can be done using ‘init’ command.
For example, when we type ‘init 3' in the command line, this will move the system from current runlevel to runlevl 3. Current level can be listed by typing the command 'who -r'

50. How can multiple machines share a single internet connection in Linux?

Linux machine can be made as a router so that multiple devices can share a single internet connection. For this, we have to use a feature called “IP Masquerade.” This functionality will help to connect multiple computers to connect to the Linux machine as well as internet. This functionality will also allow those internal computers to connect who do not have IP addresses.

                                                                                        MENU       PREVIOUS          NEXT 

No comments:

Post a comment