Redhat Linux Course RHCSA Certfication - Admin I & II: Mina Bahgat
Redhat Linux Course RHCSA Certfication - Admin I & II: Mina Bahgat
Mina Bahgat
10 October 2019
Email: [email protected]
Email: [email protected]
https://www.facebook.com/cspcourses/
https://www.linkedin.com/company/14026146/
Contents
RHCSA Guide 3
User/Group Management 3
File System 10
vi <File_name> 29
Labs 53
One 53
User/Group Management
Every process (running program) on the system runs as a particular user. Every file is
owned by a particular user. Access to files and directories are restricted by user. The user
associated with a running process determines the files and directories accessible to that
process.
cat /etc/passwd
- Description: List all the users on the system.
[root@orange ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
……………………………..
the root user can run the command authconfig--passalgo with one of the arguments
md5, sha256 or sha512.
grep apicom /etc/shadow this file contains the encrypted password as well as the
password policy parameters.
chage -M 99999 username Change the maximum days before changing the password.
chage –m 2 username the minimum days before you can change the password.
chage –W 2 username the number of days, where the system start warning the user that
his password will expire.
chage –d 0 username username will force a password update on next log in.
chage –l username will list a username's current settings.
chage -E YYYY-MM-DD will expire an account on a specific day.
date –d "+45 days” calculate date in the future.
id <username>
- Description: Check the UID & GIDs of a specific user.
This command is used to check the secondary groups of the user
[root@orange ~]# id mina
uid=2002(mina) gid=2003(mina) groups=2003(mina)
--------------------------------------------------------------------------------------------------
groups
- Description: List the groups of the user.
[root@orange ~]# id john
uid=7000(john) gid=1003(marketing) groups=1003(marketing)
[root@orange ~]# groups john
- Description: Set the primary/secondary group of the user while creating it.
[root@orange ~]# useradd -G sales Test
[root@orange ~]# id Test
uid=5001(Test) gid=5002(Test) groups=5002(Test),5001(sales)
[root@orange ~]# useradd -g sales Test_test
[root@orange ~]# id Test_test
uid=5002(Test_test) gid=5001(sales) groups=5001(sales)
[root@orange ~]#
[root@orange ~]# useradd -u 7000 -d /john –s /bin/bash john
[root@orange ~]# id john
uid=7000(john) gid=7000(john) groups=7000(john)
[root@orange ~]# grep john /etc/passwd
john:x:7000:7000::/john:/bin/bash
[root@orange ~]#
UID Ranges:
UID 0 is always assigned to the superuser account, root.
UID 1-200 is a range of "system users" assigned statically to system processes by
RedHat.
UID 201-999 is a range of "system users" used by system processes that do not own
files on the file system. They are typically assigned dynamically from the
available pool when the software that needs them is installed. Programs run as
these "unprivileged" system users in order to limit their access to just the
resources they need to function.
UID 1000+ is the range available for assignment to regular users.
Default ranges used by useradd and groupadd can be changed in the /etc/login.defs
file.
--------------------------------------------------------------------------------------------------
usermod
- Description: Change the home directory of an existing user, change his group, the
shell type ……….
[root@orange ~]# grep john /etc/passwd
john:x:7000:1002::/john:/bin/bash
[root@orange ~]# id john
uid=7000(john) gid=1002(sales) groups=1002(sales)
[root@orange ~]# usermod -s /bin/csh -d /home/john -g marketing john
[root@orange ~]# id john
uid=7000(john) gid=1003(marketing) groups=1003(marketing)
[root@orange ~]# cat /etc/passwd | grep john
john:x:7000:1003::/home/john:/bin/csh
[root@orange ~]#
-userdel <username> removes the user from /etc/passwd, but leaves the home
directory intact by default.
-userdel -r <username> removes the user and the user's home directory.
NB: When a user is removed with userdel without the -r option specified, the system will
have files that are owned by an unassigned user ID number. This can also happen when
files created by a deleted user exist outside their home directory. This situation can lead to
information leakage and other security issues.
In Red Hat Enterprise Linux 7 the useradd command assigns new users the first free UID
number available in the range starting from UID 1000 or above. (unless one is explicitly
specified with the -u UID option). This is how information leakage can occur: If the first free
UID number had been previously assigned to a user account which has since been
removed from the system, the old user's UID number will get reassigned to the new user,
giving the new user ownership of the old user's remaining files.
Depending on the situation, one solution to this problem is to remove all "unowned" files
from the system when the user that created them is deleted. Another solution is to manually
assign the "unowned" files to a different user.
-find / -nouser -o -nogroup 2> /dev/null The root user can find "unowned" files and
directories.
exit
- Description: Exit a user shell.
--------------------------------------------------------------------------------------------------
groupadd <group_name>
- Description: Add a new group.
[root@orange ~]# grep Linux /etc/group
[root@orange ~]# groupadd Linux
[root@orange ~]# grep Linux /etc/group
Linux:x:5003:
--------------------------------------------------------------------------------------------------
-[student@serverx -]$ sudo groupadd -g 5000 ateam groupadd groupname without
options uses the next available GID from the range specified in the /etc/login.defs file. The
-g GID option is used to specify a specific GID.
The -r option will create a system group using a GID from the range of valid system GID
numbers listed in the /etc/login.defs file.
groupmod
-[student@serverx -]$ sudo groupmod -n javaapp appusers The groupmod
command is used to change a group name to a GID mapping. The -n option is used to
specify a new name.
-[student@serverx -]$ sudo groupmod -g 6000 ateam The -g option is used to specify
a new GID.
groupdel <group_name>
- Description: Delete a group.
[root@orange ~]# groupdel Linux
[root@orange ~]# grep Linux /etc/group
[root@orange ~]#
-[student@serverx -]$ sudo groupdel javaapp A group may not be removed if it is the
File System
/proc The /proc filesystem contains a illusionary filesystem. It does not exist on a disk.
Instead, the kernel creates it in memory. It is used to provide information about the system
(originally about processes, hence the name).
-Not recommended to use file names containing space as this may cause undesired
command behavior.
-Absolute path of a file must starts with slash (/var/log/messages the absolute path of
the system log message file)
In Red Hat Enterprise Linux 7, four older directories in / now have identical contents as
their counterparts located in /usr:
- /bin and /usr/bin.
- /sbin and /usr/sbin.
- /lib and /usr/lib.
- /lib64 and /usr/lib64.
The directories in / are symbolic links to the matching directories in /usr.
[student@serverX ~]$
1.1.1.2 whoami
- Description: List the current logging user.
[root@orange ~]# whoami
NB: If the current working directory ~ this means the home directory of the logging user,
otherwise it wil display the last directory in the current path ([username@hostname Videos]$
the current directory is /home/students/Videos).
--------------------------------------------------------------------------------------------------
cd <directory_name>
- Description: Change directory.
[csp@localhost home]$ pwd
/home
[csp@localhost home]$ cd /home/csp/Desktop
[csp@localhost Desktop]$ pwd
/home/csp/Desktop
[csp@localhost Desktop]$ cd - return to the previous location
/home
[csp@localhost home]$ cd ~ go to home directory, same as cd without
arguments.
[csp@localhost ~]$ pwd
/home/csp
[csp@localhost ~]$ cd ..
[csp@localhost home]$ pwd
/home
[csp@localhost home]$
ls/ll
- Description: List the directory content.
ls –aiRl /redhat/sysgrp/ List the files.
-a list all the files including the hidden files, the hidden files names start
with (.)
-i List the inodes of the file.
-R List the directory content recursively.
-l List more metadata info. of the file.
-ld List more metadata info. of the directory (not its contents).
-t sort by modification time, newest first
[root@localhost ~]# ll
total 8
-rw-r--r--. 1 root root 0 Apr 10 03:07 ana
-rw-------. 1 root root 2777 Apr 3 15:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Apr 10 03:07 cat1
-rw-r--r--. 1 root root 0 Apr 10 03:07 ghghganajlkjlkj
-rw-r--r--. 1 root root 123 Apr 10 03:01 test
[root@localhost ~]# ls a*
ana anaconda-ks.cfg
[root@localhost ~]# ls *ana*
ana anaconda-ks.cfg ghghganajlkjlkj
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 2777 Apr 3 15:13 anaconda-ks.cfg
[root@localhost ~]# touch {file1,file2}.log
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 2777 Apr 3 15:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Apr 10 03:41 file1.log
-rw-r--r--. 1 root root 0 Apr 10 03:41 file2.log
[root@localhost ~]# touch file{3..6}.log
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 2777 Apr 3 15:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Apr 10 03:41 file1.log
-rw-r--r--. 1 root root 0 Apr 10 03:41 file2.log
-rw-r--r--. 1 root root 0 Apr 10 03:41 file3.log
-rw-r--r--. 1 root root 0 Apr 10 03:41 file4.log
-rw-r--r--. 1 root root 0 Apr 10 03:41 file5.log
-rw-r--r--. 1 root root 0 Apr 10 03:41 file6.log
[root@localhost ~]# touch file{a,b}{1,2}.log
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 2777 Apr 3 15:13 anaconda-ks.cfg
rm
- Description: Remove File or Directory.
[root@orange ~]# rm /Test
rm: remove regular empty file ‘/Test’? y
[root@orange ~]# ll / | grep Test
[root@orange ~]#
[root@orange mount]# ll
total 0
drwxr-xr-x. 2 root root 6 Jan 9 12:09 mount1
[root@orange mount]# rm -r mount1
rm: remove directory ‘mount1’? y
[root@orange mount]# ll
total 0
[root@orange mount]#
rm –f file this will remove the file without confirmation (force).
rm –i dir the opposite of force option it is used to delete the folder content
iteratively.
mkdir <directory_path>
- Description: Create new Folder
[root@orange ~]# mkdir /newdir
[root@orange ~]# ls /
bin boot dev dir1 etc home lib lib64 media mnt newdir opt proc root
run sbin srv sys TESt TEST tmp usr var web
[root@orange ~]#
Touch
mkdir -p used to create the directory as well as its parent one.
mkdir /Test/”x/c” we need to write the file name between “”, if the name
contains special character.
mkdir /Test/”c d”
--------------------------------------------------------------------------------------------------
export OS_USERNAME=KirillosAkram
export OS_USER_DOMAIN_NAME=KirillosAkram
export OS_TENANT_ID=
export OS_IDENTITY_API_VERSION=3
export NOVA_ENDPOINT_TYPE=publicURL
export OS_ENDPOINT_TYPE=publicURL
[root@orange ~]#
--------------------------------------------------------------------------------------------------
more
- Description: similar to cat command, it opens the file, but the difference that more
show the file contents by page, you can go to the next page by pressing SPACE.
[root@orange ~]# more /var/log/messages
Jan 9 10:44:04 orange dhclient[1242]: DHCPACK from 10.0.2.3 (xid=0x10eca753)
Jan 9 10:44:04 orange NetworkManager: DHCPACK from 10.0.2.3 (xid=0x10eca753)
Jan 9 10:44:04 orange dhclient[1242]: bound to 10.0.2.10 -- renewal in 464
seconds.
Jan 9 10:44:04 orange NetworkManager: bound to 10.0.2.10 -- renewal in 464
seconds.
--More--(0%)
--Press “q” to quit, back to the prompt.
--------------------------------------------------------------------------------------------------
1.1.1.5 less
less <file_name> similar to more.
head
by default, open the first 10 lines of the file.
head –n 5 <filename> use the option “-n” in order to change the default number of lines.
tail
It is especially helpful for reproducing problems and issues to monitor one or more log files
for events. The tail -f /path/to/file command outputs the last 10 lines of the file specified and
continues to output new lines as they get written to the monitored file.
[root@orange Documents]# ll
total 0
-rw-r--r--. 1 root root 0 Jan 12 11:04 Test
In this case the owner of the file is root and his permissions are read & write, the group of
the file is root and the group permissions is read only, the other users have permissions
read only as well.
chown
- Description: Change the ownership/group of a file.
[root@orange mount]# ll
total 0
-rw-r--r--. 1 root root 0 Jan 9 11:33 Test
[root@orange mount]# chown mina:sales Test
[root@orange mount]# ll
total 0
-rw-r--r--. 1 mina sales 0 Jan 9 11:33 Test
In this case the owner of the file is changed from root to mina, while the group
is changed from root to sales.
In this case I just changed the group of the file to test group
chgrp
chgrp groupname <dir_name> change the group ownership, we can use chown.
chgrp groupname <dir_name> = chown :groupname <dir_name>
In this case we changed the permissions for the owner by 7 (rwx), group by 7 (rwx)
& other by 7 (rwx).
4 read
2 write
1 execute
Symbolic representation
chmod go-rw <file_name>
in this case I remove the read & write permissions from the (g)group and (o)other.
chmod -R g+rwX demodir this will recursively apply the permissions on all the
tree under demodir, X will apply execute on directories only, not files.
--------------------------------------------------------------------------------------------------
umask
The system default umask values for Bash shell users are defined in the /etc /profile and
/etc/bashrc files. Users can override the system defaults in their .bash_profile and
.bashrc files, these are hidden files found in user home directory.
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login
shells. When you login (type username and password) via console, either sitting at the
machine, or remotely via ssh: .bash_profile is executed to configure your shell before the
initial command prompt.
- Description: used for determining the default permission for a new file creation.
[root@orange Documents]# umask
0022
[root@orange Documents]# touch Test
[root@orange Documents]# ll
total 0
-rw-r--r--. 1 root root 0 Jan 12 11:04 Test
Mask shows the permissions that will be masked, not the permssions that will be permitted.
ACL
Specifiy unique permissions for a user or a group.
getfacl
in order to list the current ACL for a file/directory
[test@localhost perm.test]$ getfacl test
# file: test
# owner: test
# group: test
user::rwx
group::rw-
other::rw-
[test@localhost perm.test]$ ll test
-rwxrw-rw-. 1 test test 0 Jun 13 15:49 test
setfacl
This is used to set ACL for a file.
[root@localhost perm.test]# ll
total 4
-rwxrwxrw-+ 1 test test 0 Jun 13 15:49 test
-rw-r--r--. 1 root root 0 Jun 14 09:29 test2
[root@localhost perm.test]# getfacl test | setfacl --set-file=-
test2
[root@localhost perm.test]# ll
total 8
-rwxrwxrw-+ 1 test test 0 Jun 13 15:49 test
-rwxrwxrw-+ 1 root root 0 Jun 14 09:29 test2
[root@localhost perm.test]#
ACL Mask
Mask settings show the maximum permissions possible for all named
users, the group-owner and named groups, only file owner and others
are not effected by the mask permissions.
Default ACL
Default section will appear for directories only, the default ACL
applied on the drectories will be inherated to any newly created
file in this directory.
default:user::rwx
default:user:james:---
default:group::rwx
default:group:sodor:r–x
default:mask::rwx
default:other::---
Special Permissions
If you need to control your permissions byond the normal linux permissions then you need
to use the Special Permissions.
Stickybit (on directory)
When applying permissions to directories on Linux, the permission bits have different
meanings than on regular files.
• The read bit (r) allows the affected user to list the files within the directory
• The write bit (w) allows the affected user to create, rename, or delete files within the
directory, and modify the directory's attributes
• The execute bit (x) allows the affected user to enter the directory, and access files and
directories inside
• The sticky bit (T, or t if the execute bit is set for others) states that files and directories
within that directory may only be deleted or renamed by their owner (or root
The sticky bit for a directory sets a special restriction on deletion of files: Only the owner of
the file (and root ) can delete files within the directory. An example is /tmp:
exit
ls –ld /tmp
drwxrwxrwt
Symbolically: sticky=o+t
Numerically (fourth preceding digit): sticky=1
# chmod 1777 <dir_name>
# chmod o+t <dir_name>
setgid on directory
setgid on a directory means that files created in the directory will inherit the group affiliation
from the directory, rather than inheriting it from the creating user.
A file may be removed by anyone who has write permission to the directory in which the file
resides, regardless of the ownership or permissions on the file itself.
Symbolically: setgid=g+s
Numerically (fourth preceding digit): setgid= 2
# chmod 2777 <dir_name>
# chmod g+s <dir_name>
setuid/setgid on executable files
The setuid (or setgid) permission on an executable file means that the command will run as
the user ( or group) of the file, not as the user that ran the command. One example is the
passwd command:
ls –l /usr/bin/passwd
-rws
Symbolically: setuid=u+s; setgid=g+s
Numerically (fourth preceding digit): setuid=4; setgid= 2
# chmod 4777 <file_name>
# chmod u+s <file_name>
Permissions Scenario
rx permissions on directory
Any directory needs read and execute permissions in order to cd it
[mina@localhost test]$ ll -d /test
drwxrwxr--. 2 root root 17 Apr 7 06:29 /test
in this scenario mina user is from the others, so he has read access
on the directory but not execute so he can’t cd the directory.
As u see he can’t use commands like ls, cd on the directory now let
us give others the execute permission
As u see the newly created file in the directory got the Default ACL
from the directory instead of getting it from umask
In this case I removed the default ACL related to the owner part, so
when creating a new file it gets the permissions from umask for the
owner part, while for the group and other it took it from the
default ACL.
If you are the file owner, you will get the permissions of the Owner
Only, whatever what is set for the group, other or even ACL.
[csp@localhost test]$ ll
----rwxrwx. 1 csp csp 0 Apr 7 05:03 test
[csp@localhost test]$ id
uid=1000(csp) gid=1000(csp) groups=1000(csp)
[csp@localhost test]$ cat test
cat: test: Permission denied
[csp@localhost test]$ grep mina /etc/passwd > test
bash: test: Permission denied
[csp@localhost test]$ setfacl -m u:csp:rwx test
[csp@localhost test]$ getfacl test
# file: test
# owner: csp
# group: csp
user::---
user:csp:rwx
group::rwx
mask::rwx
other::rwx
[csp@localhost test]$ cat test
cat: test: Permission denied
[mina@localhost test]$ ll
----rwxrwx. 1 csp csp 0 Apr 7 05:03 test
[mina@localhost test]$ id
uid=1001(mina) gid=1002(mina)
groups=1002(mina),1000(csp),1001(sales)
[mina@localhost test]$ grep mina /etc/passwd > test
[mina@localhost test]$ cat test
mina:x:1001:1002::/home/mina:/bin/bash
[csp@localhost test]$ setfacl -m u:mina:r test
[csp@localhost test]$ getfacl test
# file: test
# owner: csp
# group: csp
user::---
user:csp:rwx
user:mina:r--
group::rwx
mask::rwx
other::rwx
[mina@localhost test]$ grep csp /etc/passwd > test
bash: test: Permission denied
[mina@localhost test]$ cat test
mina:x:1001:1002::/home/mina:/bin/bash
[mina@localhost test]$
Summery
Linux basic permissions
Linux permissions are applied on files and directories.
Linux permissions are rwx.
These permissions are applied on 3 categories:
- file owner
- file group
- others
Change permissions
In order to change the permissons, we use chmod command
chmod 741 <filename> in this case we give rwx for the owner, r-- for the group & --x for
others.
ACL
Used to specify a specific user/group from others and give him specific permissions.
Special permissions
On Directory:
Sticky bit: it is used to let only the owner of the file to delete the file in the directory.
Set group id: it is used to let any new created file take the group ownership from the
directory not the user created the file “default case”.
On File:
Set user id/set group id: it is used to let the system consider the user executing the file as if
he is the owner or his group is the group of the file.
vi <File_name>
- Description: Most popular Linux file editor.
[root@orange home]# vi newfile
Default mode is the Command mode
i Enter insert mode, with the cursor at the same position.
I Enter insert mode, move the cursor to the start of the line.
A Enter insert mode, move the cursor to the end of the line.
a Enter insert mode, move the cursor to the next character.
o Enter insert mode, and make new line below the cursor position.
O Enter insert mode, and make new line above the cursor position.
ESC return to command mode from insert mode.
vimtutor open vim help
vim stands for vi improved, with vim u will get same vi features plus new added
features, for more info please check this link:
https://www.vim.org/viusers.php
Commands in Command mode
:wq! or x! to save & quit the file.
:w save the file, without exiting.
:set number view the line number
:<number> Jump to a specific line
j move the cursor down one line at time
k move the cursor up one line at time
h move the cursor left one line at time
l move the cursor right one line at time
dd delete the current line
dd<number> delete an number of lines starting from the one u are on.
gg Move to first line.
G Move to last line.
^ Move to beginning of the current line.
g to enable replacing more than one occurrence of pattern per line, and i, to make the
current search case-insensitive.
% for all the lines in the current document (search and replace normally only works on the
current line)
In vi editor, the space is not a special character.
Commands in INSERT mode
Home go to the first of the line.
End go to the end of the line.
Ctrl+w delete till the nearest space.
At the bottom right, you will see the current cursor position(line,character),and what part of
the file lis being displayed(All for all,Top for the first lines of a file, Bot for the bottom of a
file,or a percentage to indicate where in the file you are).The bottom line is called the Ruler
in vim terms.
[root@localhost ~]# ll
total 8
-rw-------. 1 root root 2777 Apr 3 15:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 144 Apr 11 22:33 test
[root@localhost ~]# mkdir dir
[root@localhost ~]# cp test dir
[root@localhost ~]# grep c.t .
grep: .: Is a directory
[root@localhost ~]# grep c.t *
anaconda-ks.cfg:bootloader --location=mbr --boot-drive=sda
grep: dir: Is a directory
test:cat
test:catajfgAJKGFajskfgjGSAFJafjagsjkfa
test:KJSAGDFVJKagfjkAGFJgfjkacat
test:cot
test:cut
[root@localhost ~]# grep -r c.t *
anaconda-ks.cfg:bootloader --location=mbr --boot-drive=sda
dir/test:cat
dir/test:catajfgAJKGFajskfgjGSAFJafjagsjkfa
dir/test:KJSAGDFVJKagfjkAGFJgfjkacat
dir/test:cot
dir/test:cut
test:cat
test:catajfgAJKGFajskfgjGSAFJafjagsjkfa
test:KJSAGDFVJKagfjkAGFJgfjkacat
test:cot
test:cut
[root@localhost ~]#
[root@localhost ~]# ll
total 20
-rw-------. 2 root root 2777 Apr 3 15:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Apr 12 05:12 file1
-rw-r--r--. 1 root root 0 Apr 12 05:12 file2
-rw-r--r--. 1 root root 0 Apr 12 05:12 file3
-rw-r--r--. 1 root root 0 Apr 12 05:12 file4
-rw-r--r--. 1 root root 0 Apr 12 05:12 file5
-rw-r--r--. 1 root root 3012 Apr 12 01:38 test
drwxr-xr-x. 2 root root 6 Apr 12 05:12 TEST
-rw-r--r--. 1 root root 10240 Apr 12 05:13 TEST.tar
tar xf
[root@localhost ~]# tar xf TEST.tar
[root@localhost ~]# ll
total 20
-rw-------. 2 root root 2777 Apr 3 15:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Apr 12 05:12 file1
-rw-r--r--. 1 root root 0 Apr 12 05:12 file2
This command extracts the tar file, take care u need to extract the
file in a new directory as if there is an old file in the directory
with the same name of another file in the tar, the tar will
overwrite the existing file
tar tf
[root@localhost ~]# tar tf TEST.tar
TEST/
file1
file2
file3
[root@localhost Desktop]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
ip –s link show
Description: Show statistics for network performance.
ip route
Description: Show the local routing table on the server
Ifconfig
- Description: This Command is similar to ip a command used for Redhat 6.
[root@orange ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.10 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe9d:7006 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:9d:70:06 txqueuelen 1000 (Ethernet)
RX packets 135 bytes 15248 (14.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 170 bytes 16731 (16.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@orange ~]#
--------------------------------------------------------------------------------------------------
ethtool
Description: Show the configuration of any port
/etc/services
A list of well-known and registered ports can be found in the /etc/services file.
traceroute
Description: check the route between 2 servers.
Each line in the output of tracepath represents a router or hop that the
packet passes through between the source and the final destination.
Additional information is provided as available, including the round trip
timing(RTT) and any changes in the maximum transmission unit (MTU) size.
For each hop, there are three RTT values (the default of TRACERT is to send
3 data packets to test each hop).
ping
[root@localhost Desktop]# ping -c3 192.168.188.133
PING 192.168.188.133 (192.168.188.133) 56(84) bytes of data.
64 bytes from 192.168.188.133: icmp_seq=1 ttl=64 time=0.439 ms
64 bytes from 192.168.188.133: icmp_seq=2 ttl=64 time=1.03 ms
64 bytes from 192.168.188.133: icmp_seq=3 ttl=64 time=1.10 ms
nmcli
A device is a network interface.
A connection is a configuration used for a device which is made up of a collection of
settings.
Multiple connections may exist for a device, but only one may be active at
a time.
con show
[root@localhost Desktop]# nmcli conn show List all the connections on
the system.
[root@localhost Desktop]# nmcli conn show –active Just show the active
connectios (applied on a network interface).
IP4.ADDRESS[1]: ip = 192.168.188.134/24, gw =
192.168.188.2
IP4.DNS[1]: 192.168.188.2
IP4.DOMAIN[1]: localdomain
IP6.ADDRESS[1]: ip = fe80::20c:29ff:fe25:22a1/64,
gw = ::
[root@localhost Desktop]#
con up/down
This command brings the connection up/down.
As u see the interface called ens33 was connected to connection named “Auto
Ethernet” once we bring up connection Test which is associated to the same
interface ens33, the interface disconnect from connection “Auto Ethernet”
and connects to Test connection
This is because there is only one active connection on any interface at any
time.
con mod
This command modifies any connection.
[root@localhost Desktop]# nmcli conn mod "Auto Ethernet" +ipv4.addresses
"192.168.188.135/24"
This command will add additional IP address to the connection.
As u see we have 2 IPs in this connection, the old one that was already
configured in the connection and the new one we just added.
dev status
Show the avaialable devices and their associated configurations.
dev show
Show details of a specific device “network interface”
[root@localhost Desktop]# nmcli dev show ens33
dev dis
This command disconnect the device from it’s connection
[root@localhost Desktop]# nmcli con show
NAME UUID TYPE DEVICE
Test 58b5756e-91c2-457b-ac9e-f51899a57784 802-3-ethernet ens33
Auto Ethernet 8b5aeac2-ec8d-4225-9aad-e94a3d7afb54 802-3-ethernet --
eno16777736 c563813d-d308-4988-9891-3c2556c4d60f 802-3-ethernet --
[root@localhost Desktop]# nmcli dev dis ens33
[root@localhost Desktop]# nmcli con show
NAME UUID TYPE DEVICE
Test 58b5756e-91c2-457b-ac9e-f51899a57784 802-3-ethernet --
Auto Ethernet 8b5aeac2-ec8d-4225-9aad-e94a3d7afb54 802-3-ethernet --
eno16777736 c563813d-d308-4988-9891-3c2556c4d60f 802-3-ethernet --
[root@localhost Desktop]#
nmtui
NETWORK CONFIGURATION USING A TEXT USER INTERFACE (NMTUI)
This tool is alternative to nmcli tool.
/etc/sysconfig/network-scripts/ifcfg-<name>
Save configuration files in the /etc/sysconfig/network-scripts directory.
/etc/hosts
This file is the local DNS for the server, if he can’t resolve using this
file, then the server will ask the DNS server configured in
/etc/reslov.conf
/etc/resolv.conf
This file is used to add the DNS servers IPs that the server will reach them if he fails to
resolve using /etc/hosts file.
cat /etc/resolv.conf
nameserver <IP> up to 3 servers for redundancy.
search example.com
# domain example.com
Note:
When using nmcli or editing network scripts files.
nmcli con mod ID ipv4.dns IP
nmcli con down ID
nmcli con up ID
or
cat /etc/sysconfig/network-scripts/ifcfg–ID
chronyd
The chronyd service keeps the usually-inaccurate local hardware clock (RTC) on track by
synchronizing it to the configured NTP servers, or if no network connectivity is available, to
the calculated RTC clock drift which is recorded in the driftfile specified in the /etc/chrony.
conf configuration file.
By default, chronyd uses servers from the NTP Pool Project for the time synchronization
and does not need additional configuration. It may be useful to change the NTP servers
when the machine in question is on an isolated network.
The quality of an NTP time source is determined by the stratum value reported by the time
source. The stratum determines the number of hops the machine is away from a high
performance reference clock. The reference clock is a stratum a time source. An NTP
server directly attached to it is a stratum 1, while a machine synchronizing time from the
NTP server is a stratum 2 time source.
There are two categories of time sources that can be configured in the /etc/chrony. conf
configuration file, server and peer. The server is one stratum above the local NTP server,
and the peer is at the same stratum level. More than one server and more than one peer
can be specified, one per line.
The first argument of the server line is the IP address or DNS name of the NTP server.
Following the server IP address or name, a series of options for the server can be listed. It
is recommended to use the iburst option, because after the service starts, four
measurements are taken in a short time period for a more accurate initial clock
synchronization.
To reconfigure the chronyd server to synchronize with classroom.example.com instead of
the default servers configured in the /etc/chrony. conf, remove the other server entries and
replace them with the following configuration file entry:
# Use public servers from the pool.ntp.org project.
server classroom.example.com iburst
-systemctl restart chronyd After pointing chronyd to the local time source,
classroom.example.com, the service needs to be restarted.
-chronyc sources it is useful to verify the NTP server was used to synchronize the
system clock, for more verbose output with additional explanations about the output,
chronyc sources -v.
NB: The chronyc command acts as a client to the chronyd service.
Firewall
The netfilter subsystem allows kernel modules to inspect every packet traversing the
system.
This means any incoming, outgoing, or forwarded network packet can be inspected,
modified, dropped, or rejected in a programmatic way, before reaching components in user
space.
Iptables & firewalld programs are used to interact with netfilter.
iptables
The iptables command is a low-level tool, and it can be challenging to correctly manage
firewalls with that tool. In addition, it only adjusts IPv4 firewall rules. Other utilities, such
as ip6tables for IPv6 and ebtables for software bridges, need to be used for more complete
firewall coverage.
firewalld
firewalld is a system daemon that can configure and monitor the system firewall rules.
Applications can talk to firewalld to request ports to be opened using the DBus messaging
system, a feature which can be disabled or locked down). It both covers IPv4, IPv6, and
potentially ebtables settings, not part of a minimal system install.
firewalld simplifies firewall management by classifying all network traffic into zones. Based
on criteria such as the source IP address of a packet or the incoming network interface,
traffic is then diverted into the firewall rules for the appropriate zone. Each zone can have
its own list of ports and services to be opened or closed.
Every packet that comes into the system will first be checked for its source address. If that
source address is tied to a specific zone, the rules for that zone will be parsed. If the source
address is not tied to a zone, the zone for the incoming network interface will be used.
If the network interface is not associated with a zone for some reason, the default zone will
be used. The default zone is not a separate zone itself; it is one of the other zones. The
public zone is used by default, but this can be changed by a system administrator.
Most zones will allow traffic through the firewall which matches a list of particular ports
and protocols ( "631/udp" ) or pre-defined services ( "ssh" ).
The lo interface is treated as if it were in the trusted zone.
By default, all zones permit any incoming traffic which is part of a communication initiated
by the system, and all outgoing traffic.
firewall-cmd
[csp@localhost Desktop]$ firewall-cmd --get-zones
block dmz drop external home internal public trusted work
List all zones currently in use(have an interface or source tied to them), along with their
interface and source information.
firewall-cmd --add-port=<PORT/PROTOCOL>[--zone=<ZONE>]
firewall-cmd --remove-port=<PORT/PROTOCOL>[--zone=<ZONE>]
NB:
Almost all commands will work on the runtime configuration (if the server reboots, it will br
removed ), unless the --permanent option is specified.
firewall-cmd --remove-service=<SERVICE> --permanent [--zone=<ZONE>]
a. Remove dir11 in one step. What do you notice? And how to overcome
that?
>> The command “rmdir dir11” is not accepted because it’s not
an empty file.
>>Using this command , the problem will be solved
“rm -r dir11”
b. Then remove dir12 using rmdir –p command. State what happened to
the hierarchy (Note: you are in your home dir).
>>The ‘dir12’ was deleted and ‘dir1’ must be deleted too.
5- Copy the passwd file to your home directory making its name is mypasswd.
>> cp /etc/passwd /home/mina/mypasswd
# nmcli connection add con-name eth0 ifname eth0 type ethernet ip4
172.25.9.11/24 gw4 172.25.254.254
# nmcli connection modify eth0 ipv4.dns 172.25.254.254
# nmcli connection modify eth0 ipv4.method manual
# nmcli connection modify eth0 connection.autoconnect true
# nmcli connection down eth0
# nmcli connection up eth0
# groupadd sysgrp
# useradd -aG sysgrp andrew
# useradd -aG sysgrp susan
# useradd -s /sbin/nologin sarah
# passwd susan
# passwd sarah
# mkdir -p /redhat/sysgrp
# chgrp sysgrp /redhat/sysgrp
# chmod 2770 /redhat/sysgrp
# cp /etc/fstab /var/tmp/
# chown root:root /var/tmp/fstab
# setfacl -m u:andrew:rw- /var/tmp/fstab
# setfacl -m u:susan:--- /var/tmp/fstab