20+ Scenario Based Interview Questions With Answers For Beginners and Experienced Users in Linux
20+ Scenario Based Interview Questions With Answers For Beginners and Experienced Users in Linux
IMPORTANT NOTE:
This page consists a bunch of scenario based questions and their most possible
answers, I have tried to answer to the best of my knowledge but if you feel there
could be more possible answers or if you have more list of questions and answers
which you have faced and think will be helpful for others then please do let us in
know via comment box available at the end of this page and I can add them here
on your behalf with your name so that the credit for that Q/A goes to you.
https://www.golinuxcloud.com/category/interview-questions/
A. Now just by saying ssh is not happening will not say anything about the
problem. It is like saying "I have a pain in my body" but where do you have the
pain to be precise? head ache? stomach pain? or what else? so you have to narrow
it down..
Next check the kind of error you get and then debug the problem accordingly.
3. AllowUsers and AllowGroup is defined for the target node sshd config and
hence the login fails
These are only some of the examples and the list of possible scenarios can be
many more..
Q. Suppose you have Linux box with IP, "192.168.10.11", and you are able to
ssh this node using another Linux box which has IP, "192.168.10.12", BUT
you are unable to connect to that node from another Windows Box having IP
"192.169.10.29", what could be the problem?
A. These mostly happen because of IP routing issues. Here most likely gateway is
missing in 192.168.10.12 as to connect to a node a gateway connectivity is needed
while for nodes within the same subnet can still connect to each other. A simple
ping test and trace route can give more hint of the situation.
Q. User root has created a file "secret" with below permission which must
not be opened by anyone except root and another user "deepak", how can
this be done?
# ls -l secret
# file: secret
# owner: root
# group: root
user::rwx
user:oamsys:rwx
group::---
mask::rwx
other::---
NOTE: For the sake of this example I have given full permission to oamsys but
in real all might not be needed so you can assign permission as required
But this file also must be allowed to be executed by another user "ankit", but the
problem is this script can be only executed as "deepak" user so you cannot just
use acl or any such thing here. So what is the solution?
With this argument we tell sudo to accept "-u" and "-g" option where "-u" will run
the command/script as the respective user and "-g" will do the same as respective
group.
Now if you notice here I have given RunAs access to "deepak" which means if
user "ankit" runs the script as "deepak" then he will be allowed to run the script.
$ sudo -u deepak /tmp/deepak_script.sh
Follow below link to understand more about various syntax used with sudo with
examplesTutorial / Cheatsheet:12 practical examples for different sudo access
based scenarios in RHEL 7 / CentOS 7
Q. By default when I create a user I see that the default shell assigned is
/bin/bash and the default home directory which is assigned is under /home.
How can I make sure that next time I user "useradd", the default assigned
shell is ksh and default home directory of user is /export/home/<username>
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
So either you can use additional arguments with useradd to make sure your home
directory is "/export/home" or else you can modify the above file so that without
any additional argument the home directory will be "/export/home"
Q. There are many times a root user just leaves it session open which is kind
of breach of security as any session for any user (specially root) if left idle for
certain amount of time must be closed so that no one can use it for some
wrong purpose. How can this be achieved?
A. We can introduce TMOUT variable in the profile of the user which should do
the trick.
Q. I created a password less authentication between two linux box but still
every time I try to do ssh, it still prompts me for password, what wrong could
I have done? What all I should check?
1. Make sure the public key you generated is same as what is copied to the target
node's authorised key file. In such case I always prefer to use ssh-copy-id rather
than manually copying the public key to client node.
2. The permission of .ssh directory, the generated keys and authorized keys must
not be world readable, writable or executable
Q. After upgrading kernel the machine fails to boot, what will you do?
A. The very first thing to be done here is to edit the grub menu at boot stage and
make the system boot with alternative kernel (assuming the last kernel is still
installed) or else try booting the system with using the rescue option from the
grub menu.
Once the node is UP then you can analyse the issue of why the node is failing to
boot from new kernel. Many times the kernel is not properly installed and all the
libraries are not available which leads to this problem. or the GRUB can be
corrupted so you can regerate the initramfs using grub2-mkconfig
# grub2-mkconfig -o /boot/grub2/grub.cfg
If there is a kernel panic observed then boot the system with alternate kernel or
rescue and then enable kdump. Share the kdump with the support engineers as
they can then further try to debug the source of the problem
Q. Every time I login to my Linux box instead of getting a login prompt like
"golinuxhub:~ #", I get a "-bash-4.2#" prompt, what could be the possible
reason?
A. There can be multiple reasons for it, by default when a bash shell is assigned to
a user a PS1 variable is also set which will make sure you get a proper login
prompt but for some reason if that does not happens then make sure the PS1
variable is properly set for your user.
The permanent value of PS1 is generally found in /etc/profile or can also be found
under /etc/bashrc, /etc/profile.d/* etc.
So look out for the same and make sure this file gets called every time user logs
in. By default when a user log in then ~/.profile is called so you can put the PS1
variable here or /etc/profile (assuming this file will be called internally via .profile
of each user)
For more information of PS1 variable follow below link10 examples to customize
or change the login prompt using PS1 variable of bash shell in Linux
How to change or customise login prompt for ksh shell in Linux (with examples)
How to customize and change color of the bash login prompt in Linux
Follow below link to get the steps to reset the root passwordHow to reset or
change lost root password in RHEL / CentOS 7
But assuming you have root level access then you can use pam_tally2 (deprecated
in RHEL7) or faillock to see if the user is locked for some reason.
Below link shows more examples on how to find if a user is lockedHow to check
the lock status of any user account in Linux
If a user is locked due to failed attempts then we need to reset the account
# faillock --reset --user deepak
Q. On my RHEL 7 setup the rsyslog service fails to start but the problem is
once the rsyslog server fails I do not get any messages in /var/log/messages
hence I am unable to debug or find the problem why the rsyslog service is
failing. Where should I check my system messages in such scenarios?
A. There is a variable CPUAffinity which can be used for this purpose. Use this
variable with the CPU core value with which you wish to bind your service in the
service unit file as shown below. Here my service will run always on 13th
processor
# vim /etc/systemd/system/test.service
...
[Service]
CPUAffinity=13
Type=forking
Restart=no
...
Below link contains more details on this topicHow to assign a service to a specific
core using systemd in RHEL 7 / CentOS 7
Q. I have a physical hardware with 10 CPU processors but I want to use only
6 of them and I do not my application to see the other 4 CPU processor, is it
possible?
A. We can use "maxcpus" or "nr_cpus" for this purpose. This will help limit the
number of CPU processor which is visible to the kernel or any other application
running on the system.
Follow below link to get more details with examplesHow to limit CPU count or
disable CPUs in a multi core server in RHEL 7 / CentOS 7
A. We can use "nc" here and to transfer the logs runtime to a different node in the
network which has more space.
On the receving side run below command (Either netcat or nc can be used based
on your distribution)
# netcat -l -p 55000 > /tmp/logs_from_server1.log
With this the logs will not be written directly on the node where monitoring script
is running instead it will be sent to remote server.
A. It is most likely because your BIOS date and time are wrongly set, go to your
linux server's BIOS and make sure the date and time is properly set. You should
also use ntpdate service to make sure the hwclock is updated with system clock
and both are in sync so you can avoid such discrepencies.
NOTE: If the BIOS date and time is incorrect then even ntpdate service cannot
help. It can only make sure that once ntpdate service comes up it will correct the
system log getting generated at the boot up stage in /var/log/messages
Follow below links to understand more about hwclock and NTP syncing with
hwclockHow to synchronise hardware clock (hwclock) with NTP in RHEL /
CentOS 7
How to configure NTP client to sync with NTP server during system startup
(boot) in (RHEL 7 / CentOS 7) Linux
A. This is happening because most likely the disk you are using was in use in
some more node and still has data from the old server so it is always a good idea
to clear the existing partition table of the newly connected disk. You can use
"mdadm: and "wipefs" to do this.
Follow below link for more detailsHow to clear/delete all the partition table from
a disk or partition in Linux
OR
Restart one or more units specified on the command line if the units are running.
This does nothing if units are not running. Note that, for compatibility with Red
Hat init scripts
So if the service is in not running state then the same will be untouched.
Follow below link to get know more of such commands with examplesEverything
you need to know before you start working with "systemd" in RHEL 7
All the installation logs are store inside /tmp where you can try to debug the cause
of the installation failure.
Follow below link for more detailsHow to troubleshoot kickstart related issue for
"Software selection (Source changed - please verify) in RHEL
A. To create a logfile for respctive %pre or %post section using --log argument
For example
%pre --log=/var/log/kickstart_pre.log
%end
By default, %post scripts are executed in chrooted environment. Since,
/var/log/kickstart_pre.log is available in the installers environment, you won't be
able to copy it directly. You can execute the %post script outside chroot
environment to copy the file from installers environment.
%end
Follow below link for more detailsHow to save %pre installation log file after
installation in Red Hat 7
Please post more question if you have any with the possible answer which
you wish to add here..
For more interview questions
https://www.golinuxcloud.com/category/interview-questions/