0% found this document useful (0 votes)
86 views17 pages

Self-Study: Q1. How To Check Contents of A File Without Extracting It? Explain Diff

The document provides answers to various questions related to Linux commands and concepts. It discusses: 1. How to check file contents without extracting using tar -tf and explains diff lists differences between files. 2. The main DNS record types - A, CNAME, NS, MX and PTR records and their purposes. 3. The differences between imap and pop3 protocols and their default ports. It then continues to answer questions about various Linux commands, configurations files and their purposes like uptime, cp vs rsync, /etc/rc.local, yum, umask, file permissions, usermod, ACLs, Samba ports, sudo vs su, postfix configuration files and more.

Uploaded by

TechShubh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views17 pages

Self-Study: Q1. How To Check Contents of A File Without Extracting It? Explain Diff

The document provides answers to various questions related to Linux commands and concepts. It discusses: 1. How to check file contents without extracting using tar -tf and explains diff lists differences between files. 2. The main DNS record types - A, CNAME, NS, MX and PTR records and their purposes. 3. The differences between imap and pop3 protocols and their default ports. It then continues to answer questions about various Linux commands, configurations files and their purposes like uptime, cp vs rsync, /etc/rc.local, yum, umask, file permissions, usermod, ACLs, Samba ports, sudo vs su, postfix configuration files and more.

Uploaded by

TechShubh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

SELF-STUDY

Q1.
How to check contents of a file without
extracting it? Explain diff.
Ans

tar tf filename

Note- diff command lists only the difference between two


files.
Syntax- diff first_file second_file
Q2 What are the types of DNS records?
Ans There are five types of DNS recordsa) A records Address(A) records direct a hostname to a numerical I.P
address
b) CNAMECNAME allows a machine to be known by one or more hostnames. There must
always be an A record first, and this is known as the canonical or official name. For
example:
yourdomain.com. A 192.168.0.1 .Using CNAME, you can point other hostnames
to the canonical (A record) address. For example:
ftp.yourdoman.com. CNAME yourdomain.com.
mail.yourdomain.com. CNAME yourdomain.com.
ssh.yourdomin.com. CNAME yourdomain.com.
CNAME records make it possible to access your domain through
ftp.yourdomain.com, mail.yourdomain.com, etc. Without a proper
CNAME record, you will not be able to connect to your server
using such addresses.

NAMESERVER (NS) records


Owner-Shubham Pandey
[email protected]

Email-

NS records specify the authoritative nameservers for the domain.


Be sure to put a period after the nameserver hostname in an NS record
(ns1.slamdot.com. and not ns1.slamdot.com ).
MX records
Free e-mail services such as everyone.net require that MX changes be made in
order for their software to work. This change allows mail destined for your domain
to be directed to their server. Please note that changing MX records will prevent
your current POP3 accounts, forwarders, autoresponders, and mailing lists from
functioning.
First, delete the old MX record by clicking the Delete icon under "Actions." There
should now be no MX records listed.
Next, click Create DNS Record and enter a name for your MX record. Select MX
for the type, and type in the hostname in the value field, followed by a period,
given to you by the e-mail provider. Then select the priority level (usually 10) from
the dropdown box. The priority level will also be given to you by the e-mail
provider. Click Create Record.
Note: Be sure to put a period at the end of the hostname.
To restore the original MX settings, enter yourdomain.com. and priority 0 after
deleting the other MX record.
PTR records
Pointer records (PTR) are used for reverse lookups. For example, to make
192.168.0.1 resolve to www.yourdomain.com, the record would look like:
1.0.168.192.in-addr.arpa PTR www.yourdomain.com.
Note: The IP address is reversed in the first field. Please use a period after your
hostname (second field).
The in-addr-arpa method is the most frequently used.
Important: PTR records are effective only if your site has its own IP address.
Owner-Shubham Pandey
[email protected]

Email-

Important: PTR records are only effective if named.conf is manually edited and the
proper zone information is added. This can only be done by a root user (the server
Admin).

Q2.

What is the difference between imap and pop3?

POP3 - Post Office Protocol

IMAP - Internet Messaging Access


Protocol

You can use only one computer to check your


email (no other devices)

You can use multiple computers and devices


to check your email

Your mails are stored on the computer that you


use

Your mails are stored on the server

Sent mail is stored locally on your PC, not on a


mail server
Listens on port 110.

Sent mail stays on the server so you can see it


from any device.
Listens on port 143.

Q3.
Command to know that how long system was on?
Ans uptime
Q4.
What is the difference between cp and rsync.?
Ans

cp is used to copy files or directories.

rsync is a much advanced and versatile command for


copying on local as well as remote machines as it
synchronizes with the source and copies only the changes in
the file or directories hence reducing overheads to a great
extent.
Q5.

What is the Purpose of /etc/rc.local?

Ans All the programs that need to be executed once the OS


has loaded, an entry needs to be done in this file.
Q6.

How to search a package using yum command?

Ans

yum search packagename1 packagename2.

Owner-Shubham Pandey
[email protected]

Email-

Q9
Ans

Name the file in which default umask can be set?


/etc/bashrc

Defaults
Permissions
File
Directory

Root

Umask

User

Umask

644
755

133
022

664
775

113
002

Q10
Format in which permissions can be given or
revoked?
Ans Binary
Eg- chmod 777 dir or chmod 2777 dir
SymbolicEg chmod rwx dir or to add permission -> chmod u+r dir or
chmod ugo+rw dir
Q11 What is umask?
Ans Everytime a file is created it has default permissions which
depend on umask.
Q12 How to change user and group ownership in a single
command?
Ans chown Andrew.sysusers filename
Q13 How to make a file undeletable even by root?
Ans chattr +i dir_name
To disable the above command chattr -i dir_name
To list the attributes = lsattr
Owner-Shubham Pandey
[email protected]

Email-

Note: While giving permissions root needs to make sure


that user has access to the directory where the file
resides else though the user has all permissions on the
file but he wont be able to make any changes in the file.
Q 14 How to remove a user from its secondary group?
Ans gpasswd d username groupname
Q15 How to remove all the ACLs on a file or all files in
directory?
Ans Single file- setfacl b filename/dirname
All files in a dir- setfacl R b filename/dirname
Note: When an original file is to be replaced from its
backup make sure that firstly del. The original file and
then copy the backup else permission of the original file
will automatically be applied on the backup file.
At times setfacl b may not work so in that case after
copying the file , restore its SELinux context by
restorecon F filename
Q16 What Ports are used by samba?
Ans TCP 139 & 445 ; UDP 137 & 138
Q17 How to revoke the ability of a andrew to use su or
sudo?
Ans semanage login a s user_u Andrew (policycoreutils need to
be installed for using semanage command)
Q18 What is the difference b/w su and sudo?
Ans Both commands are used to perform specific operations with
elevated privileges. DifferencesSu It forces you to share your root password with others.
Owner-Shubham Pandey
[email protected]

Email-

Sudo It makes it possible to execute system commands without


root password. It lets you use your own password to execute
system commands. Specified user(who can use sudo) needs to
have an entry in /etc/sudoers file. Make sure to use visudo
command to edit this file else it can give unexpected results
Just uncomment line no. 93
username ALL(ALL)

ALL

Q19 How to add a user with no access to login screen?


Ans useradd user s /sbin/nologin
Q20 How Email system works? From which access to
postfix can be controlled?
Ans Email messages start with mail user agent(MUA) , a client
system for sending and receiving emails such as mutt,etc . With
the help of mail submission agent (MSA) such mail is normally
sent to an MTA such as postfix and sendmail . A mail delivery
agent (MDA) such as procmail works locally to transfer this email
from server to inbox folder.
File - /etc/postfix/access
Note Except for changes in .cf files , any changes made
must be processed in the database by postmap command.
For example- If limits have been added to access file it can
be processed to binary file access.db by- postmap access
Q21 What are the functions of following files? How to
check fatal errors in main.cf ?
Ans /etc/postfix/relocated contain info of users who are now on
other networks
/etc/postfix/transport - used for mail forwading.
Postfix check
Owner-Shubham Pandey
[email protected]

Email-

Q22 How to make your system listen to all network cards?


Ans Uncomment inet_interfaces = all (/etc/postfix/main.cf)
Q23 How to configure a postfix server and allow access to
just smtp server to user1?
Ans Following entries need to be done in /etc/postfix/man.cf
my_hostname,my_domain,myorigin,inet_interfaces and
my_networks
usermod s user1 /sbin/nologin
Q24 Where is the sendmail config file located ? Which
command needs to be executed so as to apply those
changes from macro to config file?
Ans File- /etc/mail/sendmail.mc and Command - /etc/mail/make
OR make C /etc/mail.
Q25 How to switch between SMTP services(MTA)?
Ans Method 1: alternatives config mta
Method 2: system-switch-mail
Q26 State the difference between ngnix and Apache?
Ans

Nginx Vs Apache

As discussed above Nginx is based on event-driven architecture. Apache is


based on process-driven architecture. It is interesting to note that Apache in
its earliest release was not having multitasking architecture. Later Apache
MPM (multi-processing module) was added to achieve this.
Nginx doesnt create a new process for a new request. Apache creates a new
process for each request.

Owner-Shubham Pandey
[email protected]

Email-

In Nginx, memory consumption is very low for serving static pages. But,
Apaches nature of creating new process for each request increases the
memory consumption.
Several benchmarking results indicates that when compared to Apache,
Nginx is extremely fast for serving static pages.
Nginx development started only in 2002. But Apache initial release was in
1995.
In complex configurations situation, when compared to Nginx, Apache can
be configured easily as it comes with lot of configuration features to cover
wide range of requirements.
When compared to Nginx, Apache has excellent documentation.
In general, Nginx have less components to add more features. But Apache
has tons of features and provides lot more functionality than Nginx.
Nginx do not support Operating Systems like OpenVMS and IBMi. But
Apache supports much wider range of Operating Systems.
Since Nginx comes only with core features that are required for a web
server, it is lightweight when compared too Apache.
The performance and scalability of Nginx is not completely dependent on
hardware resources, whereas the performance and scalability of the Apache
is dependent on underlying hardware resources like memory and CPU.
Q27 What is the purpose of multi on in /etc/host.conf?
Ans The multi option determines whether a host in the /etc/hosts
file can have multiple IP addresses. It takes on or of as options.
This option has no effect on DNS or NIS queries.
Note Prompt for normal user $ while for root will be #.
Files that have a period(.) and the end of their permissons
are controlled by SELinux while in case of (+) sign are
controlled by ACL.
Owner-Shubham Pandey
[email protected]

Email-

Sed= stream editor


Awk= utility for db manipulation
Vim vi improved
Vipw = vim /etc/passwd
Vigw = vim /etc/group
Apart from man other doc. Help can be gained from
/usr/share/doc directory.
Q28 How can default text editor be changed?
Ans Make the following entry in /etc/environment
exports EDITOR=/bin/nano
Q29 State the meaning of different flags that are
displayed under route command?
Ans

U (route is up) . H (target is a host)


G (use gateway). R (reinstate route for dynamic routing)
D (dynamically installed by daemon or redirect).
M (modified from routing daemon or redirect).
A (installed by addrconf) .

C (cache entry).

! (reject

route)
Q30 What searches the database of man pages for
mannuals that reference to passwd command?
Ans whatis passwd arpopros
Q31 Explain nsswitch.conf file? Default port for logs?
Ans /etc/nsswitch.conf covers way more than host names: it also
covers the resolution of mail aliases, user and group names,
Owner-Shubham Pandey
[email protected]

Email-

network protocol, service and segment names and others. Port


514.
Q32 What are the config file files for configuring logging
server /client and system clock? Explain SCP with syntax
and example.
Ans Logging- /etc/rsyslog.conf
Clock- /etc/sysconfig/clock
SCP Secure Copy (uses SSH)
Syntax- scp localfile username@hostname:destination
scp username@hostname:localfile destination
Example- scp [email protected]:/var/a.txt /root/Desktop
After the above command password will be prompted and
once the correct password is entered, transfer is done.
Q 33 How to use ssh without entering password each time
you enter?
Ans It can be done by generating an ssh-keygen . It includes three
stepsStep 1

Create public and private keys using ssh-key-gen on local-host by

ssh-keygen
Step 2: Copy the public key to remote-host using ssh-copy-id
(Keep pressing enter on the prompts)

ssh-copy-id -i ~/.ssh/id_rsa.pub remote-hostname/remote I.P


Address
Step 3: Login to remote-host without entering the password
ssh remote-hostname/remote I.P

Youre done!!
Q34 How to know which package needs to be installed for a particular command?
Owner-Shubham Pandey
[email protected]

Email-

Ans yum provides /user/bin/command-name


Q35 How to change SELinux security context of a file or directory? How to run a file
in specific SELinux security context?
Ans a) chcon is used for this purpose and commonly used attributes are R for
recursive, -v for verbose, -u for user.
b) runcon is used for executing a command in specific context.
Q36 How to setup authentication on Apache webserver?
Ans Here is the sample entry of httpd.conf file
<Directory /var/www/html/help>
AuthType Basic
AuthName Password Protected Test
AuthUserFile /etc/httpd/testpass ##Be very specific about file location it should be
as stated
Require user Andrew
design user1 user2
be created

##For specifying multiple users a group needs to

and file needs to be placed in /etc/httpd/groupass


</Directory>
</VirtualHost>
While accessing server1.example.com/help
Authentication will be done (Username and password)
File passwd is placed under /var directory, which created using htpasswd utility.
htpasswd c /var/passwd username
Next password will be prompted, enter the desired password and its done.
Dont forget to restart the service.
Q37 Troubleshoot this message - httpd: apr_sockaddr_info_get() failed for
server2httpd: Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName.
Ans Just make the following entry in Apache configuration file(httpd.conf)
Owner-Shubham Pandey
[email protected]

Email-

ServerName localhost
Thats it , save the file and restart the service.

Q 38 Explain Anycast?
Ans In Internet Protocol Version 6 (IPv6), anycast is
communication between a single sender and the nearest of
several receivers in a group. Anycasting is designed to let one
host initiate the efficient updating of router tables for a group of
hosts. IPv6 can determine which gateway host is closest and
sends the packets to that host as though it were a unicast
communication. In turn, those hosts can anycast to another host
in the group until all routing tables are updated.
Q38 Explain .htaccess file?
Ans .htaccess is a configuration file for use on web servers
running the Apache Web Server software. When a .htaccess file is
placed in a directory which is in turn 'loaded via the Apache Web
Server', then the .htaccess file is detected and executed by the
Apache Web Server software. These .htaccess files can be used to
alter the configuration of the Apache Web Server software to
enable/disable additional functionality and features that the
Apache Web Server software has to offer. These facilities include
basic redirect functionality, for instance if a 404 file not found
error occurs, or for more advanced functions such as content
password protection or image hot link prevention .
Q39 Describe configuration of https ?
Ans File to be configured - /etc/httpd/conf.d/ssl.conf (If ssl.conf is not present over
there install mod_ssl package)
************************TO BE CONTINUED***************************
Q40 Describe iscsi configuration?
Ans iscsi- Internet small computer system interface
iscsiadm m discoverydb t st p 192.168.1.122 -D
Q41 Describe the configuration of VNC?
Owner-Shubham Pandey
[email protected]

Email-

Ans VNC- Virtual Network Computing


Packages required - vianagre tigervnc tigervnc-server
Configuration process- Goto /etc/sysconfig/vncservers
Uncomment the following lines and specify desired usernames in VNCSERVER
directive.
VNCSERVER=1:user1 2:user2.
##1: indicates that a connection with
user1 can be made over port 5901 2: indicates that a connection with user2 can be
made over port 5902
VNCSERVERARGS[2]=-geometery 800*600
Once its done after that you need to stop the service by
/etc/init.d/vncserver stop
Goto the particular user account mentiones in the file and run the vncserver
command.
Make sure that the port 5900 is open in you firewall.
vinagre for settings in gui mode.
vncviewer to connect to the vnc server.
Note Make sure that sharing is enabled under preference by vino-preferences
command.

Q42 Describe the functioning of the following commands?


Ans sar Collects ,reports and saves system activity info.
iostat Report of CPU,I/O statistics for devices, partiotions and NFS.
However, such reports are stored for the last seven days, depending on the
values
In /etc/sysconfig/sysstat file
Q43 Explain tar and star command?
Ans It is one of the few commands like ps who dont require (-). Few attributes
commonly used with tar areZ to compress an archive.
Owner-Shubham Pandey
[email protected]

Email-

C - to create an archive.
X - to de-compress or extract an archive.
V Verbose mode
F Perform an action Forcefully
STAR is used to archive a file in a SELinux system. To create an archive with STAR
star xattr H=exustar c f=home.star /home/
-xattr = saves the extended attributes associated with SELinux.
H=exustar = records the header associated with ACLs.
-c = creates a new archive file.
-f = specifies the name of the archive file.
To extract the above file.
star x f=home.star
Q44 Explain cron and at command in detail.
Ans Deamon for cron is crond so make sure it is running.
To block a user from creating cron jobs , make an entry in /etc/cron.deny
Config file- /etc/crontab
MAILTO cron daemon sends output by email. Just add a line such as
MAILTO = [email protected] to route all the cron messages associated with
that file to that email address.

Type

/etc/cron.deny exists

/etc/cron.allow exists

Only Users in
etc/cron.allow are allowed
for crontab e
/etc/cron.deny is ignored
Users in /etc/cron.deny are
not allowed to use crontab
e , everyon else is
allowed

/etc/cron.allow does not


exists

Owner-Shubham Pandey
[email protected]

/etc/cron.deny does not


exists
Only Users in
etc/cron.allow are allowed
for crontab e
Only the root user can run
crontab e.

Email-

Above table works the same for /etc/at.allow and /etc/at.deny .


Cron is used for mostly iterative processes .
At cant perform iterative processes.
at now + 1 hour
at>/usr/bin/echo hello
Ctr+D is used to exit the at shell.
Q45 Explain the logrotate and lastlog command?
Ans logrotate rotates , compresses and mail system logs.(By default every 7 days)
Config file- /etc/logrotate.conf
lastlog reports the most recent login of a specific or all users.
Config file for logfiles - /etc/rsyslog.conf
Q46 Explain nice and renice commands? What is the highest priority that can be set
by using nice command?
Ans Normal users can only decrease their process priority.
However root user can increase/decrease all process's priority.
Highest priority that can be set by using nice command -20
Default priority of a process is 0.
Range of priority is between 19 to -20.

nice -10 <command name> Will set a process with the priority of "10".
You can only use nice command to change the process priority
when you launch it. You cannot use nice command to change the
priority of an already running process.
In order to change the priority of an already running process you
can use "renice" command.
Some examples of renice command is as follows:

Owner-Shubham Pandey
[email protected]

Email-

renice -4 -p 3423 (this will set the priority of process id no 3423 to -4, which will
in turn increase its priority over others)
renice 13 -p 3564 -u sarath (this will set the priority of the process id 3564 to 13,
and all the process owned by user "sarath" to the priority of 13)
renice 14 -u sarath,satish -g custom (this will set all process owned by
"sarath","satish" and also the group "custom" to 14)
Q47 What is the difference between single quotes and double quotes in shell
scripting?
Ans In case of single quotes , it will echo the same thing that was entered in them
while in case of double quotes , it will echo the value of the particular variable.
Eg- a=6
echo $a

O/P- $a

echo $a

O/P - 6

Q48 How to install a specific version of a yum package?


Ans Following steps can be doneFirstly to check out which version do we have in our system
Yum info package-name
To install a specific version
Yum install package-name_with_version_no.
Q49 How to check log messages in real-time?
Ans tail f log_file_path
Q50 Where are the kernel log messages stored? Log files for remote
connections stored .
Ans /var/log/dmesg or /var/log/syslog
Owner-Shubham Pandey
[email protected]

Email-

Log files for remote connections- /var/log/secure

Owner-Shubham Pandey
[email protected]

Email-

You might also like