Linux Administration Tips

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24
At a glance
Powered by AI
Some of the key concepts discussed across the various pages include Linux administration points like vi commands, umask values, ACLs, links, user administration, file system management, DNS, DHCP, iptables, kickstart and virtual terminals.

Some ways to navigate and edit text in the vi editor mentioned are ndw to delete n words, yy and p to copy a line and paste, yw and p to copy a word and paste, o to open a new line below the cursor, Shift + o to open a line above the cursor, ndd to delete n lines, gg to move to the first line, Shift + g to move to the last line, :set nu to set line numbers, :40 to move to line 40, :w! to forcefully save and :q! to forcefully quit.

Some common Linux file system management commands mentioned are fdisk to view and manage partitions, mkfs to format partitions, mount to mount partitions, umount to unmount partitions, ln to create hard and symbolic links between files.

Linux Administration

Points discussed in the 4-day


Training session

vi

ndw deletes n words


yy and p --- > copy a line and paste
yw and p -- > copy a word and paste
o -- > opens a new line below your cursor and gets you into
insert mode
Shift + o --- > opens a line above cursor
ndd deletes n lines
gg moves to the first line of the file
Shift + 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 quit

Umask value
umask -- > default value during
installation is 022, default permission
= 644 on file and on Directory 755
To make umask value permanent edit
.bashrc

Access Control Lists(ACL)


rw- r r
RED 1
RED 2

If we want to give RED 1, RED 2 permissions without changing the


owner
and Group we use Access control List
Creating 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 ACL
It would be g:group_name instead of u:username if you want to
provide access

Links
System generated number for a file is called INODE
NUMBER
ls il <file_name> // gives the inode number
ls ial // all hidden files with inode number
mv fil2 fil3 // inode num of fil1 will be given to fil3
ln s <regular_file1> <SYMBOLIC_LINK_file2> -- creates a
symbolic link, whatever changed in file2 will be reflected
to file1
We can also create ln s <sym__link1> <sym__link2>
rm <regular_file> affects both sym_link files
If 2 files have same inode number then link count(second
column in ll) is 2
ln <FILE_1> <HARD_LINK_2> // Same inode numbers for
HARD LINKS

USER ADMINISTRATION
useradd, adduser, userdel, usermod, groupmod
Files for user administration - /etc/password,
/etc/shadow, /etc/group, /etc/gshadow
chmod
chown
usermod l nologin unix1 //unix1 will not be
able to login to the server
usermod L unix1 // lock the user account
usermod U unix1 //unlocks the user account
chage l unix2 //password policy command

File System Management

Max number of disk partitions = 15 in Linux


#fdisk l
#df h T
Print the partition table
Fdisk l
Fdisk /dev/hda //Enter the partition table
Enter n to create a new partition
w will save the partitioned table.
Update the kernel changes made inside the partition tables using #partprobe /dev/had
Validate if the partition exists #cat /proc/partitions
mkfs.ext /dev/hda(partition#)
Mount the partition onto required directory mount /dev/had /dir1
umount /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 mode
For a directory to be permanently mounted, add it to /etc/fstab
In /etc/fstab
/dev/hda6/s60 ext3 defaults
Permissions

boot priority

Jobs
#jobs displays the jobs in the
foreground
#bg displays the jobs in the
background
#ps processes running all
processes
#kill -9 pid

Logical volume Manager


Physical partition
Physical Volume
Logical Volume
Mount as many LVs

Create a Physical Partition


1. Define Physical Volume on the partition -> #pvcreate /dev/hda1
2.Define the Group Name for the partition #vgcreate vgname /dev/had
3.Extract the logical volume of required size from the physical volume #lvcreate L
+size_of_LV /dev/vg_name
4. Create file system on the Logical Volume #mkfs.ext3 /dev/vgname /lv_name
Mount the logical volume onto required directories #mount /dev/vgname /lvname
/any_directory
Enter the entries in /etc/fstab
Lv0 would be the default name for the logical volume created.

How to create a Partition


Primary Partition -> PV

Vgname
LV .LV
FS
COMMANDS
1. Fdisk /dev/had
2. n //creates a new partition
3. +500M
4. T //to change the partitions system ID
5. Mention the Partition number i.e, a number
6. L // list the partitions (Next Page A)
7. 8e // Linux LVM (Next Page B)
8. p // print the partition table
9. w // writes the partition to disk

Physical Volume to mount, from


Mount to remove

CREATE A PHYSICAL VOLUME


AND MOUNT

pvdisplay (nothing)

pvcreate /dev/hda6

pvdisplay

vgcreate volume /dev/hda6

vgdisplay

Lvdisplay

lvcreate L +50M /dev/volume6

Lvol0 created
lvrename /dev/volume6/lvol0 logic1

Lvcreate L +20M /dev/volume6

Lvol0 created
Lvrename /dev/volume/lvol0 logic2
#mkfs.ext3 /dev/volume6/logic1

Mkdir /l1, mkdir /l2

Mount /dev/volume6/logic1 /l1

Mount

Df -h

DELETING A
LOGICAL VOLUME
umount the logical
volume #umount
/dev/volume6/logic1
#lvdisplay
Vgremove
/dev/volume6
pvremove
/dev/hda6 //this will
wipe off the volume

Network Configuration
#system-config-network
Eth0 (Enter the following)
Name, Device, use DHCP, Static IP,
Netmask, Default Gateway IP
Service network restart
Ifup eth0

Boot Process

Init run levels (7 in total)


0
1
2
3
4
5
6

=
=
=
=
=
=
=

POST
Boot strap Loader
Boot Loader
Kernel
init run levels
OS Boot

Power off (All Services terminated)


Single user mode (Network interface will be broken down)
Multi user mode (cannot configure NFS)
Multi user mode (can configure NFS) (With graphical envi -> startx)
undefined
default ( has separate GUI)
reboot

Soft Links to all services is rc.d (/etc/rc.d)


-bash-3.2# runlevel
N3
If there is no previous system runlevel, the letter N will be printed
instead.

Daemon for service


Service
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.

Network
Nfs
Web
ftp
DNS
Mail
Iscsi
Iptables
NIS
dhcp
Scp/ssh
telnet

#service network stop/start/restart


#cd /etc/sysconfig/network-scripts/ifup
#chkconfig list network
#chkconfig network off

Daemons
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.

Network
Nfs
https
Vsftps
Named
Sendmail
Tgtd, iscsci
Iptables
Ypserv, ypbind, yppasswd
Dhcpd
Sshd
telnet, xinetd

Configuring yum on the


Server
All clients connect to a central repository server to
install package.
Create a partition of 4GB
Mount partition of /var/ftp
Create a directory called pub inside /var/ftp
Copy all server directory packages into pub directory
Create repository on the pub directory
Edit yum config file path to pub file
/etc/yum.repos.d/rhel-debuginfo.repo

Yum list <pkg_name>


Yum install <pkg_name>
yum remove <pkg_name>
Yum info <pkg_name>

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 <Name_of_backupfile>
<file/directory_that_we_need_to_backup>

Session management
ftp port#20(for data transfer), port 21(for FTP control)
telnet port#23
Ssh port#22
FTP
To restart ftp service #service vsftpd restart
#ftp ip_address
ftplogin:
/var/ftp/pub directory where ftp files are stored
#cat /ets/vsftpd/ftpuser //users not authorised to perform ftp
ftp> get //take files from other server
ftp>put //send to other file

NFS

NFS Linux with Linux


SMB Linux and Windows
Configuration 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 <ip_address> // list shared directories from an nfs server IP Address
Mount a directory /server50 to /client
#mount t nfs <ip_server>:/ server_folder_that_needs_to_be_shared
/folder_created_in_client_machine

SSH(Secure Server Shell )


#scp r <file/dir that you want to send> root@<server_ip:/home>

Domain Name Server(DNS)


Configuration files
Named.caching-nameserver.conf in /var/named/chroot/etc
Named.rfc1912.zones
Named.local

#service named restart


How to give a hostname
#hostname server1.linux.com //temporary
#vi /etc/hosts
127.0.0.1 server1.linux.com server1
#vi /etc/sysconfig/network -- > HOSTNAME=server1.linux.com // till here the hostname is set permanently
Named.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.conf
15: 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 GOOD
Or Else
It will show Error
Named.rfc.1912.zones
15:
27: Change the lines
Named.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 start
Block the ping requests => change 1 to 0 in
the file
#cat /proc/sys/net/ipv4/icmp_echo_ignore_all

DHCP 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.sample
Change 11 option domain_name linux.com
Change 12 DHCP IP Address
Change 21 range dynamic host 192.168.0.128-102.168.0.255
Change 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.leases

Web Service

/var/www/html - edit this file setting


To open a html file
#links any.html
#service httpd restart
#vi /etc/http[d/conf/httpd.conf

KICKSTART
Boot:linux ask method n/w inter
ftp httpd
#system-config-kickstart =>
kickstart.cfg

Altogether we have 9 login screen (7


user can be logged in)
ALT+F1+CTRL (F1-F7) Screens
#tty
/dev/tty1
ALT+F2
/dev/tty2
After ALT+F7 (It will logout of CLI)

You might also like