May 19, 2024

Part-6: Basic 10 Linux Interview Questions and Answers

In this article, we’ve included 6th set of 10 basic Linux Interview Questions and detailed answers that will help candidates prepare for the Linux interview and get the best job in the IT industry.

These Linux interview questions and answers will be useful for both freshers and experienced professionals at any level.

Some of the questions are for advanced Linux professionals, however, beginners or fresher can easily understand the answers and explanations described below.

Q.1) What is SUID in Linux

SUID stands for ‘Set user ID’, which is a type of special permission granted to a file and allows users to execute the file with the permission of its owner. There are plenty of reasons to set this type of permission for binary files on a Linux system.

The best example of a SUID is the ‘/usr/bin/passwd’ command. This binary file is owned by root user but anybody can execute this command including root. That is why SUID should be set for those binary files.

How do I identify if a file has SUID permission or not in Linux?

If a file contains ‘s’ or ‘S’ in their user permissions, it is considered a SUID permission.

ls -l /usr/bin/passwd

-rwsr-xr-x. 1 root root 31K Nov 02 2015 /usr/bin/passwd
  • s (lowercase) – Indicate SUID permissions set for the user.
  • S (uppercase) – Indicate the SUID permissions set for the user, but the executable permission “x” is not applied in that file.

How to configure SUID in Linux

To configure SUID for a file, run:

chmod u+s /path/to/file

How to find for all SUID files in Linux

To find files with setuid permissions on Linux system, run:

find / -user root -perm -4000 -exec ls -ldb {} \;

-rwsr-xr-x 1 root root 6322128 Jul 26 22:42 /usr/share/atom/chrome-sandbox
-rwsr-x--- 1 root messagebus 56808 Jun 25 17:38 /usr/lib/dbus-1/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 14392 May 31 17:21 /usr/lib/polkit-1/polkit-agent-helper-1
-rwsr-xr-x 1 root root 23368 May 30 21:54 /usr/lib/libgnomesu/gnomesu-pam-backend
-rwsr-x--- 1 root vboxusers 158352 Jul 22 15:19 /usr/lib/virtualbox/VBoxHeadless
-rwsr-x--- 1 root vboxusers 27280 Jul 22 15:19 /usr/lib/virtualbox/VBoxNetAdpCtl
-rwsr-x--- 1 root vboxusers 158344 Jul 22 15:19 /usr/lib/virtualbox/VBoxNetDHCP
-rwsr-x--- 1 root vboxusers 158344 Jul 22 15:19 /usr/lib/virtualbox/VBoxNetNAT
-rwsr-x--- 1 root vboxusers 158344 Jul 22 15:19 /usr/lib/virtualbox/VBoxSDL
-rwsr-x--- 1 root vboxusers 162448 Jul 22 15:19 /usr/lib/virtualbox/VirtualBoxVM
-rwsr-xr-x 1 root shadow 59472 May  6 21:02 /usr/bin/chfn
-rwsr-xr-x 1 root shadow 45584 May  6 21:02 /usr/bin/chsh
-rwsr-xr-x 1 root shadow 19288 May  6 21:02 /usr/bin/expiry
-rwsr-xr-x 1 root shadow 71824 May  6 21:02 /usr/bin/gpasswd
-rwsr-xr-x 1 root shadow 42104 May  6 21:02 /usr/bin/newgidmap
-rwsr-xr-x 1 root root 37176 May  6 21:02 /usr/bin/newgrp
-rwsr-xr-x 1 root shadow 37976 May  6 21:02 /usr/bin/newuidmap
-rwsr-xr-x 1 root shadow 65048 May  6 21:02 /usr/bin/passwd

Q.2) What is SGID in Linux

SGID stands for ‘Set group ID’, which is similar to SUID, but allows the file to be executed with the same permission as the group owner.

The best example of a SGID is the ‘/usr/bin/chage’ command.

How do I identify if a file has SGID permission or not in Linux?

If a file contains ‘s’ or ‘S’ in their group permissions, it is considered a SGID permission.

ls -l /usr/bin/chage

-rwxr-sr-x 1 root shadow 77280 May  6 21:02 /usr/bin/chage

To configure SGID, run:

chmod g+s /path/to/file

How to find for all SGID files in Linux

To find files with setgid permissions on Linux system, run:

find / -user root -perm -2000 -exec ls -ldb {} \;

-rwxr-sr-x 1 root utmp 10288 May 25  2018 /usr/lib/utempter/utempter
-rwxr-sr-x 1 root shadow 77280 May  6 21:02 /usr/bin/chage
-rwxr-sr-x 1 root tty 30848 May  6 20:57 /usr/bin/wall
-rwxr-sr-x 1 root tty 18552 May  6 20:57 /usr/bin/write
-rwxr-sr-x 1 root lock 10480 May 25  2018 /usr/sbin/lockdev
-rwxr-sr-x 1 root maildrop 14512 Jun 10 14:55 /usr/sbin/postdrop
-rwxr-sr-x 1 root maildrop 22656 Jun 10 14:55 /usr/sbin/postqueue
drwxr-sr-x 1 root systemd-journal 64 Mar 13 19:25 /var/log/journal
drwxr-sr-x 1 root systemd-journal 7560 Aug 28 19:50 /var/log/journal/7a138ee71db94e8785d1a4dbe54dde7e
drwxr-sr-x 2 root systemd-journal 40 Aug 29 10:59 /run/log/journal

Q.3) What is Sticky Bit in Linux

The last special permission is sticky bit. It’s configured at the directory level, which allows only the root user or owner of the file to delete them.

The best example of a sticky bit is the ‘/tmp’ directory that allows process or application to create or delete files during execution but not by other users. It basically prevents users from deleting other user’s files with in the /tmp directory because everybody has an access to the /tmp directory for read, write and delete.

ls -ld /tmp/

drwxrwxrwt. 15 root root 913408 Aug  8 15:16 /tmp/
  • t – Indicates that the sticky bit is configured for the directory.

To configure sticky bit, run:

chmod +t /path/to/directory

Q.4) What is Soft link in Linux

A soft link, also known as symbolic links, is a special type of file that points to source file or directory in Linux. It is like a shortcut in Windows that contains the path of the original file and not that contents.

Soft link can be created using the following command

ln -s [path/to/the/source-file] [path/of/the/link_name]

Q.5) What is Hard link in Linux

Hard link is a mirror copy of the original file. Deleting the original file will not impact anything, because the hard link file, will act as a mirror copy of the original file.

Hard link can be created using the following command

ln [path/to/the/source-file] [path/of/the/link_name]

Q.6) The difference between soft link vs hard link

The below table contains the difference between the soft link and hard link.

S.NoSoft LinkHard Link
1Soft link is similar to the file shortcut in Windows.Hard link is a mirror copy of the original file.
2Changes in both the files will reflect simultaneously.It works similar to Soft Link
3Soft links can be created on the different file systems.Hard link can only be created on the same file system.
4Soft link can be created for files and directoriesOnly files can be linked
5It has different inode number and file permissions compared to the original file.It has the same inode number and file permissions.
6It contains the path of the original file and not the contents.It contains the actual contents of the original file.
7When the original file is removed, the link will be inaccessible because it points to a non-existent file. This is called the hanging link.Nothing happens when the original file is removed.

Q.7) What is a zombie process on Linux?

Zombie process or defunct process is a child’s process that has completed execution but they might exist due to dead of parent processes.

Say for example, every Linux process has a parent process, which is used to kill respective child process once the child process completes their work. Also, the parent process kill itself if there is no child processes exist for them.

If the parent process is not exist then the child process is became a Zombie process or defunct process.

How to identify the zombie processes in Linux

Run the top command in batch mode to identify the zombie processes in Linux.

top -b1 -n1 | grep Z

How to find the parent of zombie processes in Linux

Execute the ps command to find the parent of zombie processes in Linux

ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }' | uniq | xargs ps -p

Q.8) What is dracut command on Linux?

The dracut is a tool, which is used to generate initramfs image on Linux system. Each time a new kernel is installed, a new initramfs is created by the dracut command.

dracut creates an initial image used by the kernel for preloading the block device modules (such as IDE, SCSI or RAID) which are needed to access the root filesystem, mounting the root filesystem and booting into the real system.

The dracut emergency shell is an interactive mode that can be initiated while the initramfs is loaded.

How to view the contents of the image created by dracut?

Use the lsinitrd command to view the contents of the image created by dracut:

sudo lsinitrd | less
or
sudo lsinitrd /boot/initrd-5.3.18-59.19-default

Q.9) What is alias in Linux?

Alias is a substitute name that refers to another command or a group of commands. It allows you to set up a user-friendly short cut command to a longer command or memorize.

How to list current bash aliases

Type the following alias command to view a list of enabled bash aliases for you on your Linux system.

alias

alias +='pushd .'
alias -- -='popd'
alias ..='cd ..'
alias ...='cd ../..'
alias beep='echo -en "\007"'
alias cd..='cd ..'
alias dir='ls -l'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias ip='ip --color=auto'
alias l='ls -alF'
alias la='ls -la'
alias ll='ls -l'
alias ls='_ls'

Q.10) How to become a root user in Linux?

You are a privileged user and would like to become a root user to perform some administration task, so how do you do that? To do so, run one of the below commands as needed.

Method-1: Using ‘sudo su’ command

The su is the simplest way of switching over to root account which requires root password to use the ‘su’ command in Linux.

sudo su -

Password:
[email protected]:/root# pwd
/root

Method-2: Using ‘sudo -i’ command

Users does not require the root password to gain root access when using ‘sudo -i’ command. Instead, users will enter their own password to avail temporary root access.

sudo -i

[email protected]:/root# pwd
/root

Method-3: Using ‘sudo -s’ command

sudo -s command provides root access and eventually protects your current environment, including shell-specific settings and the home directory.

sudo -s

[email protected]:/home/linuxgeek# pwd
/home/linuxgeek

Conclusion

In this guide, we’ve included the most frequently asked 6th set of 10 basic Linux Interview Questions and detailed answers for your reference purpose and we hope it will be very useful.

If you have any questions or feedback, feel free to comment below.

Leave a Reply

%d bloggers like this: