24
Linux Administration Points discussed in the 4-day Training session

Linux Administration Tips

Embed Size (px)

DESCRIPTION

Some Linux Administration commands

Citation preview

Linux Administration

Linux AdministrationPoints discussed in the 4-day Training sessionvindw deletes n wordsyy and p --- > copy a line and pasteyw and p -- > copy a word and pasteo -- > opens a new line below your cursor and gets you into insert modeShift + o --- > opens a line above cursorndd deletes n linesgg moves to the first line of the fileShift + g moves to the last line of the file:set nu - - > sets numbers to all lines:40 --- > moves to line 40:w! - - -> forcefully save:q! - - -> forcefully quitUmask valueumask -- > default value during installation is 022, default permission = 644 on file and on Directory 755To make umask value permanent edit .bashrcAccess Control Lists(ACL)rw- r r

If we want to give RED 1, RED 2 permissions without changing the ownerand Group we use Access control ListCreating special perissions for user RED1#getfacl Displays ACL for file#setfacl m u:red1:rw test123 // provides RW access to test123 user#setfacle x u:red1 test123 // removes the user test123 from ACLIt would be g:group_name instead of u:username if you want to provide accessRED 1RED 2LinksSystem generated number for a file is called INODE NUMBERls il // gives the inode numberls ial // all hidden files with inode numbermv fil2 fil3 // inode num of fil1 will be given to fil3ln s -- creates a symbolic link, whatever changed in file2 will be reflected to file1We can also create ln s rm affects both sym_link filesIf 2 files have same inode number then link count(second column in ll) is 2ln // Same inode numbers for HARD LINKS

USER ADMINISTRATIONuseradd, adduser, userdel, usermod, groupmodFiles for user administration - /etc/password, /etc/shadow, /etc/group, /etc/gshadowchmodchownusermod l nologin unix1 //unix1 will not be able to login to the serverusermod L unix1 // lock the user accountusermod U unix1 //unlocks the user accountchage l unix2 //password policy command

File System ManagementMax number of disk partitions = 15 in Linux#fdisk l#df h TPrint the partition tableFdisk lFdisk /dev/hda //Enter the partition tableEnter n to create a new partitionw will save the partitioned table.Update the kernel changes made inside the partition tables using #partprobe /dev/hadValidate if the partition exists #cat /proc/partitionsmkfs.ext /dev/hda(partition#)Mount the partition onto required directory mount /dev/had /dir1umount /dir1 will unmount the directory.#mount o ro /dev/had /dir1 // this will mount the partition in RO Mode#mount o remount,rw /dev/hda6 /dir1 //this will remount the partitions in RW modeFor a directory to be permanently mounted, add it to /etc/fstabIn /etc/fstab/dev/hda6/s60ext3defaults0 0

Permissionsboot priority

Jobs#jobs displays the jobs in the foreground#bg displays the jobs in the background#ps processes running all processes#kill -9 pidLogical volume ManagerPhysical partition

Physical Volume

Logical Volume

Mount as many LVs

Create a Physical Partition1. Define Physical Volume on the partition -> #pvcreate /dev/hda12.Define the Group Name for the partition #vgcreate vgname /dev/had3.Extract the logical volume of required size from the physical volume #lvcreate L +size_of_LV /dev/vg_name4. Create file system on the Logical Volume #mkfs.ext3 /dev/vgname /lv_nameMount the logical volume onto required directories #mount /dev/vgname /lvname /any_directoryEnter the entries in /etc/fstabLv0 would be the default name for the logical volume created.How to create a PartitionPrimary Partition -> PVVgnameLV.LVFSCOMMANDSFdisk /dev/hadn //creates a new partition+500MT //to change the partitions system IDMention the Partition number i.e, a numberL // list the partitions (Next Page A)8e // Linux LVM (Next Page B)p // print the partition tablew // writes the partition to disk

ABPhysical Volume to mount, from Mount to removeCREATE A PHYSICAL VOLUME AND MOUNTpvdisplay (nothing)pvcreate /dev/hda6pvdisplayvgcreate volume /dev/hda6vgdisplayLvdisplaylvcreate L +50M /dev/volume6Lvol0 createdlvrename /dev/volume6/lvol0 logic1Lvcreate L +20M /dev/volume6Lvol0 createdLvrename /dev/volume/lvol0 logic2#mkfs.ext3 /dev/volume6/logic1Mkdir /l1, mkdir /l2Mount /dev/volume6/logic1 /l1MountDf -hDELETING A LOGICAL VOLUMEumount the logical volume #umount /dev/volume6/logic1#lvdisplayVgremove /dev/volume6pvremove /dev/hda6 //this will wipe off the volumeNetwork Configuration#system-config-networkEth0 (Enter the following)Name, Device, use DHCP, Static IP, Netmask, Default Gateway IPService network restartIfup eth0Boot ProcessPOSTBoot strap LoaderBoot LoaderKernel init run levelsOS BootInit run levels (7 in total)0 = Power off (All Services terminated)1 = Single user mode (Network interface will be broken down)2 = Multi user mode (cannot configure NFS)3 = Multi user mode (can configure NFS) (With graphical envi -> startx)4 = undefined5 = default ( has separate GUI)6 = rebootSoft Links to all services is rc.d (/etc/rc.d)-bash-3.2# runlevelN 3If there is no previous system runlevel, the letter N will be printed instead.

DaemonsNetworkNfshttpsVsftpsNamedSendmailTgtd, iscsciIptablesYpserv, ypbind, yppasswdDhcpdSshdtelnet, xinetdServiceNetworkNfsWebftpDNSMailIscsiIptablesNISdhcpScp/sshtelnetDaemon for service#service network stop/start/restart#cd /etc/sysconfig/network-scripts/ifup#chkconfig list network#chkconfig network offConfiguring yum on the ServerAll clients connect to a central repository server to install package.Create a partition of 4GBMount partition of /var/ftpCreate a directory called pub inside /var/ftpCopy all server directory packages into pub directoryCreate repository on the pub directoryEdit yum config file path to pub file/etc/yum.repos.d/rhel-debuginfo.repoYum list Yum install yum remove Yum info File management#cat new >> new1 // this would apend the contents from new to new1#du h new#zcat file.gz // we will be able to view contents of zipped file#gzip#gunzip#tar cvf Session managementftp port#20(for data transfer), port 21(for FTP control)telnet port#23Ssh port#22FTPTo restart ftp service #service vsftpd restart#ftp ip_addressftplogin:/var/ftp/pub directory where ftp files are stored#cat /ets/vsftpd/ftpuser //users not authorised to perform ftpftp> get //take files from other serverftp>put //send to other fileNFSNFS Linux with LinuxSMB Linux and WindowsConfiguration file for NFS /etc/exports (by default would be empty)vi /etc/export//server_folder_that_needs_to_be_shared*(rw) -- * is used for all files#service nfs restart#showmount e // list shared directories from an nfs server IP AddressMount a directory /server50 to /client#mount t nfs :/ server_folder_that_needs_to_be_shared /folder_created_in_client_machineSSH(Secure Server Shell )#scp r root@Domain Name Server(DNS)Configuration filesNamed.caching-nameserver.conf in /var/named/chroot/etcNamed.rfc1912.zonesNamed.local#service named restartHow to give a hostname#hostname server1.linux.com //temporary#vi /etc/hosts127.0.0.1 server1.linux.com server1#vi /etc/sysconfig/network -- > HOSTNAME=server1.linux.com // till here the hostname is set permanentlyNamed.caching#cp p named.caching-nameserver.conf named.conf //backup the file#chmod 640 named.conf#chmod root:named /var/named/chroot/etc/named.conf#vi named.conf15: listen-on port 53 {192.168.10.24};23: allow-query {localhost:192.168.10.0/24;};24:allow-tranfer {localhost:192.168.10.0/24;};33:match-clients {localhost:192.168.10.0/24;};

If we do any mistKE IN ABOVE FILE LOADED SERIAL 42 -- > IF ALL GOODOr ElseIt will show ErrorNamed.rfc.1912.zones15:27: Change the linesNamed.local

IP Tables#iptables -L#iptables t filter A input s 192.168.10.55 j drop j port port# // 192.168.10.55 not accepted to the system#iptables t filter A input s 192.168.10.55 j accept // 192.168.10.55 is accepted#service iptables startBlock the ping requests => change 1 to 0 in the file#cat /proc/sys/net/ipv4/icmp_echo_ignore_allDHCP to provide IP Address#rpm qa | grep dhcp /dhcp-3package to be installed#/etc/dhcpd.conf is obtained from /usr/share/doc/dhcp/dhcp.conf.sampleChange 11 option domain_name linux.comChange 12 DHCP IP AddressChange 21 range dynamic host 192.168.0.128-102.168.0.255Change 26 host (IP_of_Server){ } //if we want multiple reservation for the client#service dhcpd restart

In the client#system-config-address -- > use DHCP#service network restart OR #dhclient

On the server#cat /var/lib/dhcpd/dhcp.leases#cat/var/lib/dhclient/dhclient-eth0.leasesWeb Service/var/www/html - edit this file settingTo open a html file#links any.html#service httpd restart#vi /etc/http[d/conf/httpd.confKICKSTARTBoot:linux ask method n/w inter ftp httpd#system-config-kickstart => kickstart.cfgAltogether we have 9 login screen (7 user can be logged in)ALT+F1+CTRL (F1-F7) Screens#tty/dev/tty1ALT+F2/dev/tty2After ALT+F7 (It will logout of CLI)