Tuesday, December 31, 2013

Giving Root Previleges to a Normal user

1. [root@testmachine Desktop]# cat /etc/sudoers

## Allow root to run any commands anywhere 
root ALL=(ALL) ALL


2. [root@testmachine Desktop]# vi  /etc/sudoers
  
go to the below line.. and add these ..

## Allow root to run any commands anywhere 
root ALL=(ALL) ALL
appu ALL=(ALL) ALL


Save and Quit.


we have given root privileges to the normal user appu.

4. To test. Login as normal user.

[appu@testmachine Desktop]$ fdisk -l

bash: /sbin/fdisk: Permission denied

So, use "sudo" before the command, it will ask you for the password. Enter your login password. If the password is correct, it will display  O/P to STDOP device(bash).

[appu@testmachine Desktop]$ sudo fdisk -l

[sudo] password for appu:*******

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b17

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        1179     9161728   83  Linux
/dev/sda3            1179        1306     1015808   82  Linux swap / Solaris

Wednesday, December 11, 2013

FTP Server Interview questions and Answers

Q. What is FTP?
FTP is a file transfer protocol, used to share files and directories.

Q: How to deny specific user’s access to the FTP Server?
To deny specific users access to the FTP server, add their usernames to the /etc/vsftpd/ftpusers file. By default, system users such as root and nobody are included in this list.

Q: Can we create logs for ftp authenticated sessions?
Yes, If the xferlog_enable directive in vsftpd.conf is set to YES, file transfers using the FTP protocol are logged to /var/log/xferlog. Information such as a time stamp, IP address of the client, the file being transferred, and the username of the person who authenticated the connection is included in the log entry.

Q: What is meaning of max_clients parameter ?
Maximum number of clients that can connect at one time. If set to 0, the number of clients is unlimited.

Q: On which port VSFTP server works ?
FTP uses two ports, 20 and 21. By default, the FTP server listens for requests on port 21. After a connection is established, the client sends commands to the server on port 21. However, port 20 is used when the server sends data back to the client.

Q: How to restart VSFTP server ?
service vsftpd restart

Q: How to allow Anonymous FTP ?
Anonymous FTP is enabled by default by setting the anonymous_enable directive in /etc/vsftpd/vsftpd.conf to YES.

Q: - For Redhat Linux or Fedora which package is required for FTP service?
Red Hat Enterprise Linux 6 or FEDORA includes the vsftpd FTP service.

Q: How to allow Anonymous FTP ?
Anonymous FTP is enabled by default by setting the anonymous_enable directive in
/etc/vsftpd/vsftpd.conf to YES.

Q: - For Redhat Linux or Fedora which package is required for FTP service ?
Red Hat Enterprise Linux 6 or FEDORA includes the vsftpd FTP service.
Check this below command, before installing FTP packages.
Rpm -qa | grep vsftpd
yum install vsftpd* -y  --------->to install vsftpd package

Q: - Important Configuration file for vsftp server?
The FTP server uses the /etc/vsftpd/vsftpd.conf configuration file

Q: - What is Passive mode?
Passive mode, like active mode, is initiated by the FTP client application. When requesting data from the server, the FTP client indicates it wants to access the data in passive mode and the server provides the IP address and a random, unprivileged port (greater than 1024) on the server. The client then connects to that port on the server to download the requested information.
When enabled, vsftpd attempts to maintain login sessions for each user through Pluggable Authentication Modules (PAM).

Q: - Is there any way to monitor clients connected to vsftpd?
Yes. We actually have two slightly different methods to monitor vsftpd clients. First, make sure you have enabled the config option, "setproctitle_enable=YES" like in our example above and restart your vsftpd server. Then run the command "watch ps -Cvsftpd -o user, pid, stime, cmd" to watch the processes including ip, username and actions like idle or data retrieval.

Q: - How to restrict some IP's not use my FTP server?
go to /etc/hosts.deny
write,
vsftpd: .example.com (or) ip addresses
save it and do the following
service vsftpd restart
chkconfig vsftpd on

Q. How much data can be send in a Single FTP session?
The amount of data which can be send is infinite. FTP uses TCP. The TCP channel can be used until the complete data is transferred. Multiple TCP segments can be used within the same TCP channel.

Q. Can an IP packet carry FTP data?
An IP packet is a carrier protocol used for carrying application layer data. The FTP data is packaged in TCP, which is sent to the intended recipient using the IP protocol in an IP based network

Q. How does Active FTP communication Work?
When a FTP client initiates a connection with FTP server in Active FTP mode, initially the FTP client initiates tcp 3 way handshake with the FTP server. This is initiated to port 21 on the server and is referred to as the control connection. Once the control connection is successful, the client responds with the port command to the server, which contains the port number to which the server needs to initiate the second TCP connection. The server initiates the connection ( 2ND tcp 3 way handshake) from port 20 on it to the port number provided by the client. This is known as data connection. Once the data connection is successful, the data transmission can commence.

Q. How many TCP connections are used by Active and Passive FTP respectively?
Both Active and Passive FTP uses two TCP connections

Q. Why does Active FTP not work when a firewall is involved between the client and the server?
In Active FTP , once the FTP client establishes the connectivity with the server, the server initiates the data connection to the client. This is a TCP connection which is initiated from a system (FTP Server) which resides outside the network. All traffic initiated from outside is considered as untrusted, and the firewall would drop it by default.

Q. How does Passive FTP resolve the issue with firewalls?
In Passive FTP, the FTP client initiates the connection with the server and not the FTP server with the client. Since the client is residing within the network , the connection is considered as trusted by the firewall.

Q. In Active FTP, which TCP port is used for initiating the control channel
Port 21




Tuesday, October 8, 2013

linux system administrator interview questions and answers for experienced

1. How to check Gateway and net mask??
Ans. netstat -ar

2. RSYNC command executed, got error while copying, again the command initiated, whether the file copies from 1st and incremental.
Ans:- The rsync command is incremental copy(check the files with destination and copies rest of the part).

3. In RAID 5, two disks are corrupted what to do ?
Ans:- In RAID 5 , if one disk is corrupted , we can replace that effective drive without any downtime. But here the scenario is  two disks are corrupted , in this case we don’t have much option left. Need to replace all the effective disks and rebuild the OS. If we kept two spare hard disk while creating RAID , the situation will be different.

4.what is hard and soft mounting?
Ans. 

    Hard mount:

— If the NFS file system is hard mounted, the NFS daemons will try repeatedly to contact the server. The NFS daemon retries will not time out, will affect system performance, and you cannot interrupt them.

   Soft mount

— If the NFS file system is soft mounted, NFS will try repeatedly to contact the server until either:
A connection is established

The NFS retry threshold is met

The nfstimeout value is reached

When one of these events occurs, control returns to the calling program.

5.what is /proc file system ?

Ans. procfs (or the proc file system  is a special file system in UNIX-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory.

6.what is daemon responsible for tracking events in a server?
Ans. syslogd


7.what is difference between raid 0 and raid 1?
Ans. RAID 0, No redundancy
       RAID 1, Redundancy

8.what is kernel panic?
Ans. A kernel panic is an action taken by an operating system upon detecting an internal fatal error from which it cannot safely recover. The term is largely specific to Unix and Unix-like systems; for Microsoft Windows operating systems the equivalent term is "bug check" (or "Blue Screen of Death").

9.what is '0' process?
Ans. parent process id of 'init' (sched process)

10.what is the last service started by init before logging screen appears?
Ans. /etc/rc.local which are the last commands run in initialization process or even booting process

11.difference between LILO &GRUB?
Ans. LILO, Linux Loader, on kernel versions < 2.4,It does'nt support booting from n/w.
     Grub, Grand unified boot loader. on Kernel versions >= 2.6, supports booting from network.


12.Stages of boot loader?
Ans.6 stages.

1. BIOS
2. MBR
3. GRUB
4. Kernel 
5. Init
6. Runlevels 


13.when two machines are there, one machine MAC & IP address is known,  another machine MAC address is there, how to find IP of another machine using command?

Ans. 'arp' command


14.while 'ping' cmd is used  the system not receiving any o/p?
Ans. ping cmd is blocked in kernel parameters

     ping  cmd uses icmp protocol.

15.Issue is there with hard drives ,dont know  which drive is fault. how to check which drive is fault?

Ans. If it is HP and IBM Servers, it will show amber color for faulty HDD.  otherwise we can see the status of the hard disks in ILO (Integrated Lights   Out)configuration for HP servers and the same remote accessing feature also available for IBM. other wise you can check in dmesg .


16.In production server one drive got failed,how to replace new drive?
Ans. plug and play devices, in raid -1 mirror is used machine can run with one hard disk . we can replace 

17.ASR means AUTOMATED SERVER RECOVERY

18. What is Network bonding? Requirements for bonding?
Ans. N/w Bonding will configure on the servers for redundancy. It requires minimum 2 Ethernet Ports/Cards.

19. MI means?

Ans. Major Incident

20. Different mount options apart from mount command?
Ans. crazy question, i will say /bin/mount., But it is mount command full form. I heared guestmount commnad also there to mount a disk ...but didn't used yet.

22.how to start services apart from 'service' cmd?
Ans. /ect/init.d/<service name> start

23.how to display memory info?
Ans. cat /proc/meminfo

   free -go (To see in GB)

24.how to display hardware information?
Ans. dmidecode |less

     Command: lscpu

List available cpus and their caracteristics , Not available on older distribution
     
     Command: lshal

         Require HAL (Hardware Abstraction Layer) to be installed . List all hardware visible by HAL

     Command: lshw

          Available on Debian and Ubuntu based distributions by default .Available in the Fedora repositories .Uses many inputs            to detect all hardware: Kernel, HAL, DMI, etc. use ‘-html’ switch that generates hardware reports
    
     Command: lspci

     Standard command ,List all hardware connected to the PCI bus as detected by the kernel
     
     Command: lsusb

      Standard command. List all hardware connected to the USB buses as detected by the kernel

     Command: dmidecode

      Standard command, Get the source information from the DMI (a kind of BIOS interface) .List all hardware as reported by       the DMI interface

25. command to check the directory's partition or mount ?

Ans. df -P file/goes/here | tail -1 | cut -d' ' -f 1

[root@testmachine Desktop]# df -P /boot/ | tail -1 | cut -d' ' -f1

/dev/sda1


26.how to rollback application?

Ans.  insert 'ts_flags=repackage' in /etc/yum.conf and create file /etc/rpm/macros with an entry'repackage' parameter.

27.how to rollback filesystem?
Ans. If 'Snapshot'(backup) is taken, using superblocks we can rollback file system.

28. Newly attached hard drive is not recognizing how to make it active ?
Ans. After building server with 2 hard disks, again if we attach any hdd, server wont recognizes it. if the server want to recognize it, we need to reboot it and create RIAD fo that HDD also.

If we replaced Faulty hard disk with new one, Server will take 1 hr time to synchronize the data (RIAD 1 and RAID 5).


29.Different raid levels & explanation?
Ans. raid 0, raid1, raid1+0, raid 1+0, raid3, raid 5, raid50, raid6.

30.file system is full? user need some space to run his work ?
Ans. 1. If it is configured with 'lvm' we can extend it, or else we can make use of reserved blocks.
     2. Delete the old files after getting confirmation from user.
     

31. How to check a package is installed or not?

Ans.  rpm -qa | grep <package name>, it will gives package name and version, if it installed, returns empty screen if not installed.

32.how to check which ports are working?

Ans. netstat cmd

33.how to configure static route?
Ans. vi /etc/sysconfig/network-scripts/ifcfg-route0

34. How to check the processor type ?

Ans. grep "model name" /proc/cpuinfo

[root@testmachine Desktop]# grep -i "model name" /proc/cpuinfo  | cut -d: -f2

 Intel(R) Core(TM)2 Duo CPU     T9550  @ 2.66GHz


35.what is GRUB?
Ans. Grand unified Boot loader. Its boot loader in linux. (kernel versions >=2.6)

36.how to check info of  hard drives ?
Ans. df or mount

37.difference between rpm and yum ?
Ans.

38.How to increase physical memory in steps?
Ans. Hardware job, Its requires a down time form the users/customers , to upgrade memory modules . (memory size should be match with old memory modules.)


40.kernel patching?
Ans. 

41.how to mount alternate superblock command?
Ans. mount  sb=alternative superblock  /dev/sda

42. How to create a never expire passwod for user?
Ans. chage -E -1 username 

43. tune2fs command used for ?

Ans. for tuning  the file system parameters

44. I am sharing a directory through samba , everything is accessible apart  from soft link files ,how to share those soft links shares?
Ans. Apply parameters in share definition
         follow symlinks =yes
         wide links =yes

46.what is the way to set dump and fsck options in /etc/fstab?
Ans.

47.maximum file grow in ext4 filesystem?
Ans. The ext4 file system can support volumes with sizes up to 1 exbibyte (EiB) and files with sizes up to 16 tebibytes (TiB). However, Red Hat recommends using XFS instead of ext4 for volumes larger than 100 TB.

1 exbibyte = 260 bytes = 1152921504606846976bytes = 1,024 pebibytes
1 tebibyte = 240 bytes = 1099511627776bytes = 1024 gibibytes

48.difference between linear and mirror volumes?
Ans.

49. scenerio 
# df -h
……………. file system full 
#ls -l 
two files…..1. one file is occupying full space
# rm -f filename
#df  -h 
same output …file system is full 
#ls -l 
file is not there ..still file system is full.
Ans.
 # lsof | grep "(deleted)" # (or lsof | grep (filename))

If it's safe to do so, take the pid from the lsof command, and do:

Code:
# ls -l /proc/(pid)/fd # to get the fd# for the file
# > /proc/(pid)/fd/(fd#) # to empty the file.

Otherwise the space will be freed when the application using it closes, or the system restarts.

# implies a root prompt, meaning your sysadmin needs to do this.

(S)he will need to install lsof if it's not already installed.

50.what is webstack? how to improve performance and bottlenecks?

Ans.

51. No such file or directory error?
Ans. ls -ld <filename>, error, no such file or directory.. 

  Reasons: Check it , by logging as a root. might be normal user not having the permissions to view it.
  we will get these type of messages, if the directory or file is unmounted or deleted.


52.how to check database and other applications running?
Ans. ps -ef | grep <database name/ application name>

53.mpstat, iostat,vmstat statistics define?
Ans.
   1. iostat – Basic example

Iostat without any argument displays information about the CPU usage, and I/O statistics about all the partitions on the system as shown below.

 #iostat
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db)       07/09/2013

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           5.68    0.00    0.52    2.03    0.00   91.76

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda             194.72      1096.66      1598.70 2719068704 3963827344
sda1            178.20       773.45      1329.09 1917686794 3295354888
sda2             16.51       323.19       269.61  801326686  668472456


   vmstat : vmstat by default will display the memory usage (including swap) as shown below.

#vmstat

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache     si   so    bi    bo   in   cs us sy id wa st
 0  0 305416 260688  29160 2356920    2    2     4     1    0    0  6  1 92  2  0

Procs – r: Total number of processes waiting to run
Procs – b: Total number of busy processes
Memory – swpd: Used virtual memory
Memory – free: Free virtual memory
Memory – buff: Memory used as buffers
Memory – cache: Memory used as cache.
Swap – si: Memory swapped from disk (for every second)
Swap – so: Memory swapped to disk (for every second)
IO – bi: Blocks in. i.e blocks received from device (for every second)
IO – bo: Blocks out. i.e blocks sent to the device (for every second)
System – in: Interrupts per second
System – cs: Context switches
CPU – us, sy, id, wa, st: CPU user time, system time, idle time, wait time


mpstat – Display basic info

By default mpstat displays CPU statistics.


54. how to list newly attached hardware?
Ans. dmidecode | less

55.In RAID , statistics display  "_U" .what is the meaning?
Ans. one of the hard disk is failed.

56.what is initrd? what it does?
Ans. initrd stands for Initial RAM Disk. initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware parts of the server.


58.where /proc file system rests?
Ans. Linux systems store all data as files. Most users are familiar with the two primary types of files: text and binary. But the /proc/ directory contains another type of file called a virtual file. As such, /proc/ is often referred to as a virtual file system.

59.where tmpfs stores?
Ans. Tmpfs is a file system which keeps all files in virtual memory. Everything in tmpfs is temporary in the sense that no files will be created on your hard drive. If you unmount a tmpfs instance, everything stored therein is lost. tmpfs lives completely in the page cache and on swap, all tmpfs pages currently in memory will show up as cached

60.Daemons in nfs?
Ans. mountd ,nfsd,lockd,statd,nfslogd

61.how to change user access to entire file system?
Ans. chown -R

62.why UMASK is used, where to change its value to be effective on entire OS?
Ans. When user create a file or directory under Linux or UNIX, it creates with a default set of permissions. In most case the system defaults may be open or relaxed for file sharing purpose. For example, if a text file has 666 permissions, it grants read and write permission to everyone. Similarly a directory with 777 permissions, grants read, write, and execute permission to everyone.


You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux machines set it to 0022 (022) or 0002 (002). 
Open /etc/profile or ~/.bashrc file, enter:
# vi /etc/profile

OR

# vi ~/.bashrc

Append/modify following line to setup a new umask:

umask 022

Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user's environment at login).

63.how to display the list of specific  port ?
Ans. netstat -ntlp | grep <service daemon name>


68.what is SFTP?
Ans.secure file transfer protocol, a network protocol for secure file transfer over a secure shell.


69.Top responding slowly..other option to check load average?
Ans. vmstat

71.Difference between crontab and at ?
list crontab entry?
Ans.crontab -l

72.what is MTA?
Ans. Mail Transfer Agent

73.while install rpm package, progress reports already use , but  no package name doesn't exist in rpm  list ?
Ans. rpm --reinstall <package name>

74.create user in different directory?
Ans. useradd -m -d  /newdir/<username>  username

Thursday, August 22, 2013

/dev/null: Permission denied

Error name: /dev/null: Permission denied 

I got this  error message while  Logging (doing ssh) into  one production server.   Please do the Following things to fix it. It doesn't requires any reboot and it wont effect to production.

testmachine11:~ # ls -ld /dev/null
crw------- 1 root root 1, 3 Apr 22  2012 /dev/null


It is a character file, The permissions should be  666 for this one. So , change the permission to 666. after that you wont see that message. 

testmachine11:~ # chmod 666 /dev/null

testmachine11:~ # ls -ld /dev/null

crw-rw-rw- 1 root root 1, 3 Apr 22  2012 /dev/null

(OR)

You can delete it and recreate the /dev/null file. But first solution is little bit faster.  

To Remove it..

     #rm -f /dev/null

 To create the special file for /dev/null 
      #mknod /dev/null c 1 3


This creates the /dev/null special file that is a special character file with the major device number 1 and the minor device  number 3.

Then start the sshd service

 # /etc/init.d/sshd start

 # /etc/init.d/sshd status


Wednesday, July 31, 2013

Linux basic commands for a beginner

To See System Information:

who -b -shows last rebooted time
cal – Show this month's calendar
uptime – Show current uptime
w – Display current logged in users
whoami – tells ur user id
uname -a – Show kernel information
less /proc/cpuinfo – CPU information
less /proc/meminfo – Memory information
df – Show local partitions 
du – Show directory space usage
date – Show the current date and time
free – Show memory and swap usage details
ls - to list the files in current directory
ls -a - to list the hedden files
less var/log/messages - to see system log messages
mail - to see mails

To get help for unkonuwn Commands

man -k keyword – Display man pages containing keyword
man command – Show the manual for command
man -t man | ps2pdf - > man.pdf  – Make a pdf of a manual page
which command – Show full path name of command
time command – See how long a command takes
which <commnad> – will gives the full path of command

To Find and search:

grep <word>  <filename>– Search for a word in the filename
command | grep <word> – Search for a particular word in the output of command

ex: who | grep <username>

find / -name filename – It will search for file called filename in / directory

find / -name ”*filename*” –  It will search for file containing the string filename in / directory.


File Permissions


chmod 777 <filename>– read, write, execute for all
chmod 755 <filename>– rwx for owner, rx for group and world

read=4
write=2
execute=1

7=read+write+execute


For more options, see man chmod.


commands related to directory levels:

cd dir – Change directory to dir
cd – Change to home
mkdir dir – Create a directory dir
pwd – Show current directory
rm name – Remove a file or directory called name
rm -r dir – Delete a directory dir
rm -f file – remove a file forcefully
rm -rf dir – Force remove an entire directory dir and all it’s included files and subdirectories 

cp file1 file2 – Copy file1 to file2
cp -r dir1 dir2 – Copy dir1 to dir2
cp file /home/dirname – Copy the file called filename to the /home/dirname directory

mv file /home/dirname – Move the file called filename to the /home/dirname directory
mv file1 file2 – Rename or move file1 to file2; 

ln -s file link – Create symbolic link link to file
touch file – Create a 0kb file or update file
cat > file – Places standard input into file
cat file – Display the file called file

more file – Display the file called file one page at a time, proceed to next page using the spacebar
head file – Display first 10 lines of file
head -20 file – Display the first 20 lines of the file called file
tail file – Output the last 10 lines of file
tail -20 file – Display the last 20 lines of the file called file
tail -f file – Output the contents of file as it grows, starting with the last 10 lines

Network

ifconfig – List IP addresses for all devices on the local machine
ping host – Ping host and output results
dig domain – Get DNS information for domain
dig -x host – Reverse lookup host
nslookup <hostname>-to check IP address
netstat -ar - to see gate way and netmask

 Remote Login

ssh <hostname> – To logged into to another server.


User Administration

adduser accountname – Create a new user call accountname
passwd accountname – Give accountname a new password
su – Log in as superuser from current login
exit – Stop being superuser and revert to normal user


Process Management

ps – Display your currently active processes
top – Display all running processes
kill <pid> – Kill process id pid
killall proc – Kill all processes named proc (use with extreme caution)
bg – Lists stopped or background jobs; resume a stopped job in the background
fg – Brings the most recent job to foreground
fg n – Brings job n to the foreground


Shutdown and restart

shutdown -h now – Shutdown the system now and do not reboot
halt – Stop all processes - same as above
shutdown -r 5 – Shutdown the system in 5 minutes and reboot
shutdown -r now – Shutdown the system now and reboot
reboot – Stop all processes and then reboot - same as above
startx – Start the X system
init 1 - to switch to rum level 1