Saturday, 22 June 2013

FIND and grep Command

Q: Find all files owned by user1, and copy it to the /root/user2 directory while perserving the permission


  1. first find how many required files are available of for user1
  2. find / -user user1
  3. mkdir /root/user2
  4. find /home -user user1 -exec cp -p {} /root/user2 \;
  5. ls -al /root/user2 (to verify all files are available)
  6. or run find / -user user1 again, it will show files available in /root/user2 as well


Note:  '-p' preserves the user/group/chmod permissions

Q: To redirect the contents of /etc/passwd to another file

#cat /etc/passwd > /user/test

#grep root /user/test | sed 's/root/ROOT/g' | sort > /home/user/file1.txt

Configuring File Services, FTP

#yum install vsftpd
#service vsftpd restart
#chkconfig vsftpd on


Note: Home/default directory of anonymous(unknown)/FTP user is /var/ftp/
Default user: FTP Password: FTP
FTP allows anonymous users to login, without password but it doesn't allow normal user to login with credentials.
Below is login with ftp/ftp

Now login with user subh/subh

FTP didn't allow access of home directory of normal user because  Selinux Booleans for 'ftp_home_directory' is 'off'.
Now we set Selinux Booleans for 'ftp_home_dir' to 'on'
#setsebool -P ftp_home_dir on    --> It takes time, as the change is permanent.
#getsebool  -a | grep ftp
Now we will try login ftp with user 'subh/subh:

To come out of FTP, use 'bye'




Configuring Web Services, HTTP

#yum install httpd           --> You need to be root to install any package.
#service httpd restart
#chkconfig httpd on       --> It will ensure httpd will be started on the required run level

Note: Home/default directory of httpd is /var/www/html/

Download the file from the given URL in the question to your home directory or to the location mentioned using wget:

Now we have to copy this file 'index.html' from home directory to '/var/www/html'
#cp index.html /var/www/html
Note: Refrain using 'move' unless mentioned in question. Because 'mv' will not allow to open the web page due to the selinux set up.

If in exam 'move' is mentioned, do below steps:
#mv index.html /var/www/html
#cd /var/www/html
#restorecon *                --> It sets the selinux of the selinux context of the file similar to the parent folder

Configuring Printer

Note: Hostname/IP of printer will be given in question
#system-config-printer
You will get below window:
Click on 'New'
Click on 'Network Printer'
Click on 'Internet Printing Protocol' (IPP)
Host: As per Question
Queue: /printer/LLC (Don't remove /printer, add your printer name given in question after '/printer/')

Click on 'Forward'
Select "Generic" if nothing is mentioned in question.
Click 'Forward'

Click 'Forward'
'Printer Name': Modify as per Question
Click on 'Apply'

LDAP and autofs

#system-config-authentication
You will get below window:
Select 'LDAP' from 'User Account Database' tab.

LDAP Search Base DN: Enter as per question
LDAP Server: Enter as per question
Check "Use TLS to encrypt connections
Click on 'Download CA Certificate
You will get below window:
Enter 'Certificate URL' : Given in question.
Click on 'OK'
Select 'LDAP password' from the 'Authentication Method'
Click on 'Apply'

Question will also ask to configure that ldap user ldapuser15 should get his home directory using autofs and should have read write access

#getent passwd ldapuser15
(if we do su - ldapuser15 without configuring autofs then it will complain that no home directory available)

then congiure the autofs (ensure it will have nfs version 3)

  1. #vim /etc/auto.master
    1. enter following in the line
    2. /home         /etc/auto.ldap
  2. #vim /etc/auto.ldap (this file will not be there, we need to create it)
    1. enter following in the line
    2. ldapuser16       -rw,vers=3     <nfs/ldap server name>:/home/guests/ldapuser16
  3. service autofs reload
  4. chkconfig autofs on





Configuring NTP

#system-config-date

You will get below window:


Check Synchronize date and Time over network.
Click 'Add'
Enter IP as per Question.
Click on the line below that, i.e. white box
After clicking it will start checking whether entered IP is reachable or not. 
Now click on 'Advanced Options' . (Ensure, your added IP is selected before clicking on advance)

Check 'Speed up initial synchronization'.
Click 'OK'

IP Forwarding

#vim /etc/sysctl.conf

   <line no7>
   net.ipv4.ip-forward = 1              --> Default will be 0(zero), we have to make it 1(one)

Save & Quit

#sysctl -p
#sysctl -a

You may get some error like "unknown key". Ignore it

CRONTAB

#crontab -l                  --> lists crontab job
#crontab -e                 --> edits crontab

Q: How to edit crontab for a specific user ?
=> #su - user
        #crontab -e
          OR
       #crontab -e -u user

Q: How to block a user from using crontab ?
=>  #vim /etc/cron.deny
         <username>
      Save & Quit

Format of crontab: 

    *             *             *             *             *          <command>
 min            hr          Date      Month    Day
(0-59)     (0-23)       (1-31)    (1-12)     (0-7)
                                                           0->Sunday
                                                           7->Sunday

Q: Write a crontab, Message="HappyBday", should be displayed on the home directory of user Natasha in a file bdya.txt, every year 12:00 AM , 23rd March.
=> #crontab -e
    0 0 23 3 * echo "HappyBday" >> /home/natasha/bday.txt

Note: '>' means Overrite and '>>" means Append.

Note: Append to a file when question explicitly mentions that.

Ensure you are root if you are running System Commands. eg. system-config-date

Configuring YUM

#cd /etc/yum.repos.d
#vim client.repo
[server]
name=rhel6
baseurl=ftp://192.168.0.101/pub/Server          --> It will be given in question
gpgcheck=0                        --> Zero


Save and Quit

#yum repolist                   --> It will list all the configured yum
# yum install ftp               --> To verity that yum installation is working so we are installing ftp client

Configuring Static IP


#system-config-network
Unselect DHCP using space, and enter below details:

given in exam instructions
Hostname:
IP :
Subnet Mask :
Gateway :
DNS/Name Server :

Set all above as per exam guidelines

#service network restart
#chkconfig network on
#ifconfig -a
#ifconfig eth0
#ifup eth0

#ping <gateway>   -->check if its pingable, if yes. it has got IP

Above may not work, so make it persistent using below:

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

         <ONBOOT=yes>

Save and quit.

Put the hostname in following file
#vim /etc/sysconfig/network
HOSTNAME=station9.domain.example.com

Friday, 21 June 2013

Breaking root password


  1. Keep pressing 'esc' during booting.
  2. Press 'e' edit.
  3. Move Selection to 2nd line.
  4. Press 'e' edit
  5. Enter ' 1' -->one space 1
  6. Press enter
  7. Press 'b' boot
  8. Now your system is in single user mode
  9. Check selinux status  #getenforce
  10. Set selinux to 0(zero) i.e. disabled/permissive  #setenforce 0
  11. Now change password  #passwd
  12. Set selinux to 1, i.e. Enforcing  #setenforce 1
  13. Make the changes persistent in #find /etc -name selinux --> /etc/sysconfig/selinux 
  14. #vim selinux -->SELINUX=permissive/disabled/enforcing
  15. Reboot your system  #init 6