$cp source dest | it willl make a copy of the file in the destination. |
$cp -r source dest | it will make a copy of the folder in the destination. |
$cp –rvf /root/* dest | it will copy all files from root folder to dest with confirmation. |
$cp –rvfn /root/* dest | it will copy only new files and not override existing file. v=display, f=forcefully, n=newfiles. |
Service Name | Daemon Name |
SSH | SSHD |
HTTP | HTTPD |
NFS | NFS-SERVER |
DNS | NAMED |
#systemctl status sshd |
Show status of sshd service or systemctl is-active sshd or systemctl is-enabled sshd (enabled means permanently) |
|
#systemctl stop sshd |
To stop sshd service. It is temp stopped until reboot. Systemctl start sshd (restart) |
|
#systemctl disable sshd |
It will stop permanently. systemctl enable sshd. |
|
#systemctl reload sshd |
Service will reload, it is effective when you make changes. Users will not be disconnected. |
|
#systemctl restart sshd |
Service will restart and all connected users will disconnect. |
|
Target |
4 types you can set |
Graphical.target: system state in gui mode multi-user.target,: system state in command line rescue.taget: O/S troubleshooting emergency.target: emergency mode |
#systemctl get-default |
To check the system state mode |
|
#systemctl isolate multi-user.target |
It change the system state to command line mode. If you check systemctl get-default it shows graphical.target as it set temp. if system reboot it will start in graphical mode. |
|
#systemctl Set-default multi-user.target |
For permanent set system state into command line mode. |
|
#Systemctl Poweroff |
|
|
#Systemctl Reboot |
|
/ top level root directory. | |
/root: it is a home directory for root user. | /bin: contain commands used by normal users. |
/Home: It is a home directory for normal users | /sbin: contain commands used by root user. |
/boot: it contain boot files. | /etc: system configuration files. |
/tmp: stored temporary data. | /dev: disk information is stored. |
/lib 32 & 64: stored libraries. | /opt: contain and stored third party software |
/proc: process information. | /mnt: information about mounting. |
/run: media device which helps to run. | |
#cat > filename | It creates a file and you can enter text. Ctrl D to save. |
#cat >> filename | Add new lines only. Cannot delete existing lines. |
#cat 2 > filename | |
#cat filename | To view/read file. |
#cat –n filename | Displays with line numbers |
#du –sh filename | Displays file size. |
#stat filename | file status and access time. |
#cp source dest | it willl make a copy of the file in the destination. |
#cp -r source dest | it will make a copy of the folder in the destination. |
#cp –rvf /root/* dest | it will copy all files from root folder to dest with confirmation. |
#Cp –rvfn /root/* dest | it will copy only new files and not override existing file. v=display, f=forcefully, n=newfiles. |
Empty File Creation: touch,
#touch filename location | it creates empty file |
#touch abc{1..10} location | it will create files abc1 to abc10. |
#touch .file1 | It will create hidden empty file. |
Edit File: vi or vim,
vi filename |
Create a file in editor. if file exist it open in editor mode.
|
options | i = insert mode. q! = Exit, wq! Save and exit. x = Delete character where cursor blinking, 4x delete 4char. dw = Delete a word. dd = Delete a line. gg = Cursor goes to top. shift g = Cursor goes to bottom. u = undo. ctrl r = Redo.
|
List files and folders: list,
#ls | List files and folders of current location. |
#ls -l | Long list |
#ls -a | List all files and folders including hidden. |
#ls -la | Long list of files and folders including hidden. |
#ls -lt | List of files with time stamp, latest created file on the top. |
#ls-R | List directories and all its sub directories. |
#ls-hl | Displays size of the file. |
Ls-lr or ls-ltr | List of files with recently updated. r in reverse order |
Folder Creation: create, delete,
#mkdir foldername location | creates folder. |
#mkdir .foldername | creates hidden folder. |
#mkdir –p parent/child | creates parent folder and child folder inside parent folder. |
#rename oldname newname oldname | oldname newname oldname |
#mv sourcefolder dest | It will move folder from source to destination location. |
#mv sourcename destiname | it will copy file in the same location with new name. |
#rm -r foldername | it will delete folder. |
#rm –rvf | delete folder, v= display folder wich will delete, f= forcefully |
directory | owner | group owner | other | acl(.=no advance permission, +=acl) |
root user default d | rwx | r-x | r-x | . |
normal user d | rwx | rwx | r-x |
file | owner | group | other | no acl |
root user | rw- | r-- | r-- | . |
normal user | rw- | rw- | r-- |
no permission=0Execute permission oly = 1
write permission only =2
write and execute permission =3(2+1)
read permision only = 4
Read and execute permission= 5(4+1)
read and write permission = 6 (4+2)
read,write & execute permission = 7 (4+2+1)
#Ls –ld /folder1 (drwx r-x r-x. 2 root root 10 sep 13:35 /folder1), assign full permission to group.
#chmod 775 folder1 (drwx rwx r-x. 2 root root 10 sep 13:35 /folder1
Method1: Add user1 to group and assign permission to group.
Usermod –G root user1 (groups user1: will display groups of user1)
Method2: groupadd dev
Chgrp dev /folder2 (ls –ld /folder2/) now group owner from root changed to dev.
Add a user to group dev (usermod –G dev user1)
Add user1 as owner of the folder2
chown user1 /folder2
Change both owner and group owner
chown root:root /folder2 (root will be the owner of folder and group) (chown=change file owner and group)
you can do this way: chmod u=---, g=---,o=--- /folder2 or chmod ugo=rwx /folder2 or chmod ugo-x /folder2 or chmod +x /folder2 or chmod –x /folder2.
Syntax: $find location options argument | |
$find / -name aziz | it will find aziz from / root location. |
$find / -readable | it will find readable permission files from root location |
$find /root empty | it will find empty files in /root directory. |
$find / -perm 444 | find files whose permission is 444 |
$find / -size 10M | find files whose size is 10M |
$du -sh filename | Find size of the file |
|
$grep root /etc/passwd |
It will find/search root word in passwd file and display those lines on screen. |
option -n |
$grep -n root /etc/passwd |
It will search and display the line numbers on which root word exist. |
option -i |
$grep –ni Root /etc/passwd |
Ignore case sensitive (word with upper or lower case will be ignored) |
option -on |
$grep -o root /etc/passwd |
It will only display word in the line, will not display the entire line. |
option '^word' |
$grep '^root' /etc/passwd |
It will only display line where word root comes at the beginning of line. |
option -A number |
$grep -A 2 root /etc/passwd |
it will display root line and 2 lines after word root from file. |
option -B number |
$grep -B 2 root /etc/passwd |
it will display root line and 2 lines before word root from file. |
|
$egrep –in ‘root|ftp|nologon’ /etc/passwd |
Used for multiple words to search. |
option -R |
$grep -Rin root /etc |
it will seach the entire folder for work root. |
|
$grep –in ‘Sep’ /var/log/messages |
It will display logs of Sep |
|
$grep –in ‘Sep 05’ /var/… |
It will display logs of sept 5 |
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
at |
|
It is used to schedule a job only once. Make sure at job available in the system, rpm –qa | grep –I at, its daemon is atd. |
|
at 12:50 at> touch abc at>touch file1 ctrl D |
At 12:50 time it schedule a job and creates two files abc & file1 or you can define particular time and date. at 12:00 PM October 20 2020 or at noon tomorrow, at next Monday, at fri |
atrm |
atrm 4 |
Remove job with job number |
atq |
|
Displays scheduled job list |
crontab |
|
It is used to schedule job continuously or repeatedly. |
|
rpm -qa | grep crontab |
To check crontab module is installed. yum install crontab. Systemctl start crond. |
Syntax |
Cat /etc/crontab |
It will display syntax. (Min, hour, day, month, day of week, username, command) |
|
crontab -e |
It opens an editor, here you write command using above syntax 39 09 01 jan 03 root echo “welcome” >> test.txt save it. If you use * in minute then it will run every minute. If you use */2 run every 2 minutes. |
|
crontab -l |
It displays list of scheduled jobs |
|
watch cat test.txt |
It will open a file and we have define job schedule in every minute. |
|
crontab -r |
Delete. |
|
Crontab -u username -e |
Run crontab with a particular username. |
|
Tail -f /var/log/cron |
Check logs. |
|
Crontab -r -I -u username filename |
|
|
Sleep 60 |
|
|
Cd /etc/cron.hourly |
Here you keep script, this file normally used in day to daty scheduling jobs in real time scenario instead of crontab, |
|
|
|
#echo “message” |
It will print message on screen only. |
#echo “message” > filename |
It will store message in a file. |
Hard disk types: SATA (Serial Attach) and PATA(Parallel Attach)
SATA (disks: sda, sdb, sdc,… partitions sda1, sda2, sda3.. sdb1, sdb2, sdb3..)
PATA (disks: hda, hdb, hdc,.. partitions: hda1, hda2, hda3.. hdb1, hdb2, hdb3)
Maximum partitions : 4 (4 primary only) or (3 primary + Extended (in extended logical No.n)
Format : ext2 (RHEL4), ext3(RHEL5), ext4(RHEL6) xfs (RHEL7)
Disk Partition:
Disk & partition |
fdisk–l |
Display disks & partitions. |
|
lsblk |
Display disks & partitions in a tree format. |
|
lsblk –l |
Display disks & partitions in list format. |
Create partition |
fdisk /dev/sdb |
In order to create partitions first you need to enter into disk, all disk info is stored in /dev. Enter m will give list to perform actions. |
|
|
|
Update kernel |
partprobe |
After creating a new partition or making any changes in partition kernel need to update with partprobe command. If you try to format without partprobe system will give error partition does not exist. Reboot the system will update kernel without using partprobe. |
|
partprobe /dev/sdb |
It will update particular hard disk. Partbrobe only will update kernel for all disks. |
Format partition |
blkid |
To check partition is formatted or not. Data can be saved after formatting the newly created partitions. If partitions are not shown in the list it means it is not formatted. After formatting you can save data. |
|
Mkfs –t ext2 /dev/sdb1 |
It will format the partition. Ext1, Ext2, Ext3,Ext4, XFS is the file system. |
Create a directory/file to mount |
Mkdir /dev/sdb1/partition1 |
First create a directory and then mount this directory and then you can save data. |
Mount partition |
Mount /dev/sdb1 /partition1 |
After creating new partition, partprobe, format need to mount the partition to save the data. After mounting you can save data. |
|
|
|
Display mount partitions |
Df –h |
It will display all partitions that are mounted. |
|
|
|
|
|
|
Unmount partition |
Umount /partition1 |
When you reboot this mount will not exist. |
Mount permanently |
Vim /etc/fstab |
To mount partition permanently even it exist after reboot. |
|
Make an entry |
/dev/sdb1 /partition1 ext2 defaults 0 0 save it. |
|
Mount –a |
This will update entries made in fstab. |
Format |
Mkfs –t ext3 /dev/sdb2 |
It will format sdb2 partition. Copy UUID |
Mount with UUID |
Mkdir /partition2 |
Go to vim /etc/fstab and make entry with UUID. UUID=”jldfjawje” /partition2 ext3 defaults 0 0 |
|
Mount –a |
|
Vfat |
|
If you partition with vfat then it will work with windows system while ext will not. |
|
Mkfs –t vfat /dev/sdb5 |
Make partition and mount. |
|
Mkfs –t xfs /dev/sdb6 |
Partition using xfs, make folder and mount. |
Unmount |
Umount /partition1 |
Go to fstab and delete those lines. Save & mount –a. now go to fdisk –l and delete partitions. Partprobe /dev/sdb |
Swap partition |
Free -h |
It will display swap partition details. |
|
Swapon -s |
|
|
|
Add hard disk for swap memory and reboot/ partition create. |
|
Mkswap /dev/sdb1 |
Create a swap |
|
Swapon sdb1 |
It will activate.when reboot it will disappear. |
Mount |
Vim /etc/fstab |
Entry: dev/sdb1 swap swap defaults 0 0 save it and run mount -a |
Deactivate |
Swapoff /dev/sdb1 |
Go to fstab and remove entry and run mount -a and remove partition if needed. Partprobe /dev/sdb |
Swap partition through file, if partition limit is full then you can use a space in the hard disk and create a file and this file use as swap partition. |
||
Create |
dd if=dev/zero of=/swapfile bs=512mb count=2 |
Create a file take a space from hard disk and create a file at root level. Block size will be 512 mb and count two times means will create 1024 mb or 1GB. |
|
du -sh |
It will display size of the created file. |
|
mkswap /swapfile |
Create a swap. |
|
swapon /swapfile |
Activate it. Give permission 600(chmod 600 /swapfile) |
|
Vim /etc/fstab |
Entry: /swapfile swap swap defaults 0 0 save it then run mount -a |
Deactivate |
Swapoff /swapfile |
|
|
Rm -rf /swapfile |
Delete file. |
Systemctl |
Reboot (alias of systemctl) |
Gracefully reboot system |
|
Init 6 |
Forecefully reboot |
reboot |
Shutdown –r 15:50 |
Reboot at 15:50 |
|
Shutdown - +15 |
Reboot after 15 min |
|
Shutdown –r now |
Reboot now |
|
Shutdown –c |
Cancel reboot. |
|
Shutdown –r now |
Reboot now |
Shutdown |
Shutdown –h now |
It will shutdown now. |
#rpm –qa |
It will display all packages installed. |
|
#rpm –qa | wc –l |
Total number of packages installed. |
|
#rpm –qa firefox |
It will display firefox is installed or not. |
|
#firefox |
Browser will open or can be opened from application |
|
#rpm –ev firefox |
E is for erase and v for verbose (you can view the process) |
|
Install firefox
|
On VMWare with GUI |
vmware settings: select vm>settings>use ISO image and browse location of image. click on cd/dvd icon in bottom and connect. CD icon appears on desktop. Go to RHEL folder in CD>package> search firefox, copy package and paste on desktop and install. |
Install with RPM #rpm –ivh firefox……. |
#df –h (To check CD iss mounted), cd /run/media/root/RHEL7.0/serverx86 and cd/Packages, #ls #rpm –ivh firefox….. press tab and install. |
|
#rpm –Uvh firefox |
It will install update |
|
#rpm –ivh forefox –force |
Forcefully it install |
|
YUM |
It is used to install packages in Centos. |
|
|
Yum list all |
It shows all packages |
|
Yum repolist |
It list repository |
|
Yum list installed |
It list those package who are installed |
|
Yum list httpd |
|
|
Yum list nfs-utils |
|
|
Yum info httpd |
|
|
Yum reinstall httpd |
|
|
Yum update httpd |
|
|
Yum remove httpd |
Yum autoremove httpd (it will remove dependencies) |
|
Hum history |
|
|
Yum history info 4 |
It shows details of ID 4 installed |
|
Yum history undo 4 |
It will undo the ID 4 (uninstall) |
Logs |
cd /var/log |
Tail –F yum.log |
|
Yum search all “web server” |
It shows webs server package |
|
Yum search all “mail server” |
It shows mail server package |
|
Yum search all “dns server” |
It shows dns server package |
|
Repository |
Local and network. |
create |
Local repository |
Create a folder mkdir /examplerpm Copy data from CD to /examplerpm (all files from CD incl repodata copied). cd /etc/yum.repo.d vim /example/repo [example] name =file:///examplerpm enabled = 1 gpgcheck = 0 save this file run yum clean all yum repo list (when you run yum command it will search in this file) all rpm files are in Package folder and how does system knows? It will look repodata and if found then proceed installation. repodata will inform where is rpm files are stored. |
create |
repodata |
Mkdir/software/itrpm (create folders) Createrep /software/ cd /etc/yum.repo.d vim itrpm.repo baseurl =file:///software enabled = 1 gpgcheck = 0 save it |
|
yum repolist |
It will list repo files created. |
Amend |
update repodata |
If you add/delete any rpm then repodata need to be update. Createrepo --update /software/ |
|
|
|
Network Repository |
|
Repodata created in network server. |
|
|
|
It allows a user to execute a command as a super user. By default superuser(root) have got all administrative privilege but it is mostly locked and we create normal user and assigned required roles or permission to perform their task. You can run command with administrative privilege by using sudo.
$sudo fdisk –l (it will ask password to confirm user, if this user is in sudo file then it works)
To give access to a user to run such commands first get the command binary
#which fdisk –l (it will display binary of the command)
Go to sudoers file by vim /etc/sudoers
se –nu (it will display line numbers) go to line 100 and press o to insert a line.
username ALL=(ALL) ALL (this user can run all commands which root can)
if you want a user to give permission to a particular command then instead of all type
username ALL=(ALL) /sbin/fdisk, /sbin/useradd save it.
If you want to give full permission except few restriction then
Username ALL=(ALL) ALL,!/sbin/reboot, !/sbin/useradd, !/usr/bin/passwd (now user cannot reboot, cannot create user and assign password) save it.
To assign similar permission to another user, copy the line & paste and change username. The best example is create a group and assign permission to that group and add required users to that group.
groupadd security (created a security group).
Gpasswd –M user1,user2,user3 security (to check user added run grep security etc/group)
Now go to vim /etc/sudoers and add group
%security ALL=(ALL) ALL
When a user run command using sudo system ask for password, you can skip this by
Username ALL=(ALL) NOPASSWD:ALL save it.
Alt+F2 type Gnome-terminal |
It will open a terminal. |
ctrl+D |
Close terminal |
Alt&shift+++ |
It will increase font size. |
Alt&--- |
It will decrease font size |
Alt+F10 |
Window full size |
Alt+F5 |
Window normal size. |
root@hostname:~# |
root = user name, @ hostname(hostname or IP), ~ (tild sysmbol shows you are in home directory of root user, when you change directory it shows directory name), # denotes you are root user. |
aziz@hostname:~$ | aziz =user name, @hostname,(hostname or IP) ~ is the user home directory, $ denotes normal user,
Normal User UID = 1000 to 60000 GID 1000 to 60000 (this range can be increased in /etc/login.defs). |
System User | DNS, DHCP, FTP, Apache, Samba, NFS etc.. used to manage services, 1 to 999 GID (1to999) in RHEL7, in RHEL6 UID =1to 499 & GID=1 to 499. |
UID (user ID) and GID (Group ID) is assigned to a user and all policies are assigned to that ID. | |
#cat /etc/passwd user information stored in this path. |
root:x:0:0:root:/root:/bin/bash root = user’s login name x = password pointer /etc/shadow, password is set (! = password is not set): 0 =UID 0 = GID root = comments (define designation of user, administrator, manager etc..) root = user’s home directory /bin/bash = login shell
|
# /etc/shadow Password information is stored in this path. |
root: xfaddoiuabelrje : : : : : : : (9 fields) root = username X39u3lkaefj = password in encrypted format 3 to 9 fileds= stored user password policies.
|
#/etc/group Group information is stored in this path. |
root:x:0: ziz, Abdul, user1, user2
|
#/etc/gshadow Group password stored in this path. |
Root: aoplw2lj fl : aziz : user1, user 2 (4 field)
|
#/var/mail/root |
Mail information is stored in this path. |
User creation with password assigned: without password user cannot login. Root user can switch to any user even the user has password has not been assigned.
useradd user1 (user created without password)
passwd user 1 (system prompt to assign password)
user to user switch: user can switch another user by assigning password, exit to come out.
user to root switch: user cannot switch to root user.
Check password assigned? Passwd -S user1 (S = status).
Password Lock : passwd -l user1 (password locked, user to user switch login denied, root user can login), passwd -S user1 (check password status)
unlock password: passwd -u user1 (password unlocked)
passwd -S user1 (check password status)
password delete: passwd -d user1( user password deleted)
passwd -S user1 (Password status check)
user creation using script and assigned a password:
vim usercreation.sh (press i to go to insert mode)
#! /bin/bash
useradd user10
echo India123| passwd - -stdin user10 (press esc)
:wq! (save script)
RUN SCRIPT
sh usercreation.sh (user created with password assigned)
passwd -S user10 (check password status)
User Account Policies:
Chage -l user1 (shows account aging information)
Chage user1 (to reset the account options)
To change a particular record, chage -option newvalue username (chage - -help check)
tar options archivefoldername file&folder, create a folder and go to folder and run
tar –cvf redhad.tar /etc (c for create, v for verbose, f for file type) it start archiving.
du –sh redhad.tar (display size = 30 mb, before archive it was 34 mb)
tar –xvf redhad.tar (it extract files in the same location and display contents of tar file)
tar –xvf redhad.tar –C /tmp/ (it will extract in tmp folder)
tar –tvf redhad.tar (list files)
tar –zvf redhat.gz /etc (it will compress etc folder as rehat.gz)
tar –zcvf rehat.tar.gz /etc (it will archive and compress)
du –sh redhat.tar redhat.gz (30 mb redhat.tar and 8.4mb redhat.tar.gz)
tar –jcvf redhat.tar.bz2 /etc (using gunzip command to archive and compress)
du –sh redhat.tar redhat.tar.gz redhat.tar.bz2 (30 mb, 8.4 mb, 7.0 mb)
tar –Jcvf redhat.tar.xz /etc (using xz command, J is capital)
du –sh redhat.tar.xz (5.7 mb)
tar –zxvf redhat.tar.gz (It will extract, use x instead of c)
tar –jxvf redhat.tar.bz2
tar –Jxvf redhat.tar.xz
Zip: to check zip is installed (rpm –qa zip) (rpm –qa unzip)
zip abc.zip /etc (it will zip etc folder in abc.zip)
du –sh abc.zip (size 4.0k)
unzip abc.zip (it will unzip)