0% found this document useful (0 votes)
15 views

Redhat Admin 1

Uploaded by

mohamed9ahmed12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Redhat Admin 1

Uploaded by

mohamed9ahmed12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Redhat Admin 1

1965 - MIT & GE & Bell Labs Multics OS

1968 - Bell Labs (AT&T) Unics OS Unix1, Unix2

Students took Unix + Some APPs and Made


1976 - Berkeley University Bell Labs Made a License
BSD (Berkeley Software Distribution)

1983 - Richard Stallman Retired from Bell Labs and Started his own Project GNU (Open Source)

1991 - Linus Torvalds Made some enhancements to unix kernel


Linux History
GNU + Linus's Kernel = GNU Linux

1995 - Windows Came with GUI Xorg made Xprotocol (Linux GUI)

Redhat = Linus Kernel + Richard's GNU +Xprotocol + Apps Made RHEL and Fedora

Debian Made the Same thing and Came up with Debian and Ubuntu

CentOS

Vmware or Virtual Box


Linux Installation
ISO

Root User ID = 0

Linux Users Service Users 0 < User ID < 1000

Standard Users User ID >= 1000

/ Contains all the file system

/root Contains the root home directory Desktop, Downloads,Documents.....

/home Contains a Directory for each User Ex: /home/mohamed/ Desktop, Downloads........

/bin Contains the binary files of the Commands Ex: the binary files of the ls, cd, mv commands

/sbin Contains the binary files of the System Commands Ex: the binary files of the useradd, userdel Commands

Browsing the File System /etc Contains Configuration Files

/tmp Contains Temporary Files

/var Contains variable size files Ex: logs files

/dev Contains Device files

/proc Contains Currently Running Processes files

/boot Contains boot loader(grub) and kernel

cd Change Directory Ex: cd /home/ali

pwd Print Working Directory Output: /home/khaled/Desktop

ls -a List all files including hidden files

ls -l Long listing (list files with some information)

ls List all files in a directory ls -r Reverse List

ls -R Recursive

ls -d directory info

cp Copy files from source to destination Ex: cp file1 /home/ali/Desktop

mv Move or Rename files Ex: mv file1 /home/ahmed/Desktop Ex: mv file1 file2

mkdir Make a new directory Ex: mkdir directory1

rm delete files Ex: rm file1

su Switch User used to change the current logged in user Ex: su - root

passwd change user password Ex: Passwd khaled

useradd add a new user Ex: useradd Mohamed

userdel Delete a user Ex: userdel Mohamed


Running Commands and
Command <Options> <Arguments>
Getting Help head display the first 10 lines of a text file Ex: head file1.txt

tail display the last 10 lines of a text file Ex: tail file1.txt

wc Word Count Display the Number of lines, words and characters of a file Ex: wc file1

cat

more

whatis

groupadd Ex: groupadd sales

-G overwrite
usermod Ex: usermod -G sales mohamed
-a append

Ex: gpasswd group1 -a mohamed

gpasswd used for group administration Ex: gpasswd group2 -M khaled,ahmed,mohamed

Ex: gpasswd group3 -d hassan

-L show password aging info Ex: chage -l khaled

-M Maximum Days

-m Minimum Days
chage
-I Inactivity

-E Account Expiration YYYY-MM-DD

-W Warning days

mount /dev/sdb1 /home/ahmed/Desktop/dir1


Mount , Unmount Devices Located in /dev/sda1 or sdb1 .....
umount /home/ahmed/Desktop/dir1

ifconfig Show Interface and IP Information

ifdown InterfaceName Disable Interface

ifup InterfaceName Enable Interface

Interface Configuration File Can be Found /etc/sysconfig/network-scripts/ifcfg-interfaceName


Network
hostname Server1 Changes the host name to server1 the result will be root@server1 will be reset after reboot

edit /etc/hostname file Changes the host name Permanently

hostnamectl set-hostname server5 Changes the host name Permanently

Dns Cache LocalDns "/etc/hosts" Resolver "/etc/resolv.conf"

Password ssh User@IP

Generate Public + Private Key in /home/yourUserName/.ssh


SSH ssh-keygen -t rsa
you can Enter Passphrase to protect your Key

Key Based Copy Your /home/yourUserName/id_rsa.pub


ssh-copy-id RemoteUser@IP
to remote Server in /home/remoteUserName/.ssh/authorized_keys

ssh -i /home/yourUserName/.ssh/id_rsa RemoteUser@IP Login to Remote Server with your Private Key (without Password)
Remote Login
scp source destination:file from our Machine to remote server
SCP
scp source:file destination from remote server to our machine

put used to upload a file to the remote server


SFTP sftp user@IP
get used to download a file from remote server

Ex: add user to "wheel" group

Sudoers File gives user administrator privileges (use sudo command) Ex: nano /etc/sudoers

Ex: visudo

ls -l 1> outputfile 2> errorfile ">" overwrite ">>" append


Output Redirection
ls -l &> file1 output and error in the same file

tr 'a-z' 'A-Z' < /etc/passwd Input Redirection


I/O Redirection , Piping , Tee
Piping gets the output of a command and use it
Ex: head -5 /etc/passwd | tail -2 | tr 'a-z' 'A-Z'
as the input of the next command

tee stores the output to a file then execute the


Ex: head -5 /etc/passwd | tee f1 | tail -2 | tee f2 | tr 'a-z' 'A-Z' > f3
rest of the command

every file has an owner, group and other each one has his own permission

Owner " u " , Group " g " , Other " o " , All " a "

Ex: chmod u=rwx , go=r file1


Symbolic Read " r " , Write " w " , Execute " x "
Ex: chmod u+x , g-w file1

Grant " + " , Deny " - " , Set " = "


we have to ways to change a permission

rwx = 4+2+1 = 7
Ex: if we want a file permission to be rwx rw- r--
Numeric Read = 4 , Write = 2 , Execute = 1 rw = 4+2+0 = 6
we will use the following comand: chmod 764 file2
r = 4+0+0 = 4

chgrp used to change the group of a file Ex: chgrp sales file1

Users , Groups , Permission Ex: chown owner:group file1


Ex: chown mohamed:sales file1
chown used to change the owner of a file
Ex: chown :Marketing file1

Enables any user to run a file with the Owner


Set User ID (SUID)
Privileges

Special Permissions Inherit Group Ownership to all of the files


Set Group ID (SGID)
created in that directory

Sticky Bit Only the Owner of the File can delete it

Change the default Permission of a user Ex: umask 027


umask
user umask is 002 by default , root umask is 022

Command Mode Press " i " to Enter insert mode

Insert Mode Press " ESC " to get back to Command mode

Exit in Command mode use " :w " to write " :wq " to write and quit " :q! " to exit without saving
Vim
' / ' used to search

type 6 then press shift + g Jump to Line Number 6


Commands
'dd' to Delete a line

'A' used to append Jump to the end of a line and enter insert mode

yum Centos 7 Package Manager

dnf Centos 8 Package Manager

yum install nano Checks the Repository and start installing nano Repositories Could be Found at /etc/yum.repos.d

Package Management yum repolist View enabled repos

yum clean all Remove the Repo data

yum remove PackageName used to remove a package

yum search apache search for a package ( result will be httpd )

Ex: service httpd [status, start, stop]


service ServiceName Action
Ex: chkconfig httpd on

Ex: systemctl start httpd


systemctl Action ServiceName
Ex: systemctl enable httpd
Service Management
netstat -ltpn View Listening Ports

Managed by firewall-cmd

firewall service firewall-cmd --list-all

firewall-cmd --add-service=http we can add --permanent so we don’t lose the configuration after reloading firewall

cut used to extract a column Ex: cut -f 1,3 -d : /etc/passwd

Text Processing grep "khaled" /etc/passwd

grep used to extract rows matching a criteria grep -A2 "khaled" /etc/passwd

grep -B2 "khaled" /etc/passwd

the fastest way to search for a file in linux but it’s using a pre-built database of
locate paths to files on the system Ex: locate file1
DataBase must be updated by admin using "updatedb" Command

Ex: find /home/khaled -name file1


Searching in Linux
Ex: find /home/khaled -iname file1 ignore case sensitive

Ex: find /home/khaled -user khaled -group khaled


find is used to search for a file with a criteria find StartingDirectory Criteria
Ex: find /home/khaled -user khaled -o -user ali

Ex: find /var/log -size +1M

Ex: find -name "*".txt -delete

c = Create an archive
t = list an archive
x = extract files from an archive
tar is an archiving tool in linux tar cvf ArchiveName Files... v = verbose
f = file name
z = use gzip compression
Archiving j = use bzip2 compression

zip -r ArchiveName.zip /etc unzip ArchiveName.zip to extract

ps Display Active Process

ps -aux display all processes and users

Kill ProcessID Terminate a Process

kill -9 PID Force Kill

Ex: pkill firefox


pkill ProcessName
Ex: pkill -u khaled

pgrep Process grep Ex: pgrep bash display bash process id

Process Management pidof bash display the process id of bash

nice -n -15 sleep

renice -n -15 PID

sleep 10 & run process in background

jobs view background processes

fg % 1 return process number 1 to foreground

ctrl + z stop a process

bg % 2 resume a process in background

Can be Found at
Global /etc/bashrc
/etc/profile
Startup Files
~/.bashrc
User-Specific
~/.bash_profile

* Any string of zero or more characters.

? Any single character.

[abc...] Any one character between the square brackets

[!abc...] Any one character not in the enclosed class.

Wild Cards [[:alpha:]] Any alphabetic character.

[[:lower:]] Any lowercase character.

[[:upper:]] Any uppercase character.

[[:alnum:]] Any alphabetic character or digit.

[[:digit:]] Any single digit from 0 to 9.

You might also like