Linux Training : Section 5 (Part-2)
Module 5 - System Administration
Table of contents
Process Management
Background =
cntl+z, jobs and bg
Foreground =
fg
Run process even after exit =
nohup process
& ORnohup process > /dev/null 2>&1 &
Kill a process by name =
pkill
Process priority =
nice
(e.g.nice -n 5 processs
)- The niceness scale goes from -20 to 19. The lower the number more priority that task gets
Process monitoring =
top
List process =
ps
System Monitoring
Commands-
top
- display linux processesdf
- report file system disk space usagedmesg
- print or control the kernel ring bufferiostat
- monitoring system input/output statistics for devices and partitions.netstat
-ip
&ss
- a command-line tool that displays network status and statistics.free
- provides information on how much memory is being used on the system, including RAM, buffers, and cached data.cat /proc/cpuinfo
- cpu informationcat /proc/meminfo
- memory information
Logs Monitoring
Log Directory- /var/log…Important files under this directory-
boot
chronyd
= NTPcron
maillog
secure
messages
httpd
System Maintenance Commands
Commands-
shutdown
= Shutdown the systeminit
= Service managerreboot
= Reboot the systemhalt
= It stops the CPU
Changing System Hostname
hostnamectl set-hostname newhostname
location- Edit /etc/hostname
Finding System Information
cat /etc/redhat-release
uname -a
dmidecode
System Architecture command -
arch
: it is used to check the 32bit or 64bit CPU
Terminal Control Keys-
CTRL+U
- erase everything you’ve typed on the cmd lineCTRL+C
- stop/kill a cmdCTRL+Z
- suspend a cmdCTRL+D
- exit from an interactive program (signals end of data)
Terminal Commands-
clear
- clears your screenexit
- exit out of the shell, terminal or a user sessionscript
- the script cmd stores terminal activities in a log file that can be named by a user, when a name is not provided by a user, the default file name, typescript is used.
Recover Root Password-
Steps-
Restart your computer
Edit grub
Change Password
Reboot
SOS Report
Collect and package diagnostic and support data
Package name:
sos-version
Command:
sosreport
Environment Variables
An environment variables is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.
In simple words; set of defined rules and values to build an environment
Commands-
To view all env variables -
printenv
ORenv
To view ONE environment variable -
echo $SHELL
To set the environment variable -
export TEST-1
»echo $TEST
To set the environment variable permanently -
vi .bashrc
»TEST=‘123‘
»export TEST
To set global environment variable -
vi /etc/profile
or/etc/bashrc
»TEST=‘123‘
»export TEST
Special Permissions-
There are 3 additional permissions in Linux-
setuid: bit tells Linux to run a program with the effective user id of the owner instead if the executor(e.g.,
passwd
command) » /etc/shadowsetgid: bit tells Linux to run a program with the effective group id of the owner instead if the executor(e.g.,
locate
orwall
command)NOTE: setuid and setgid is not the actual cmd to set, we will use chmod command.
sticky bit : a bit set on files/directories that allows only the owner or root to delete those files.
in the permission “t“ has been assigned, so that expect owner, no body can delete this!!
To assign special permissions at the user level
chmod u+s xyz.sh
To assign special permissions at the group level
chmod g+s xyz.sh
To remove special permissions at the user or group level
chmod u-s xyz.sh
chmod g-s xyz.sh
To find all executables in Linux with setuid and setgid permissions
find / -perm /600 -type f
NOTE: These bits work on C programming executables not on bash shell scripts
Hands-On:
Become root and create a directory allinone in / = mkdir /allinone
Assign all rwx permissions to that directory = chmod 777 /allinone/
Become aditya and create directory inside of /allinone = mkdir adityadir
Give all rwx permissions to that directory = chmod 777 adityadir
Create 3 files in that directory = touch a b c
Open another terminal and login as thor
Go to /allinaone directory and delete adityadir directory = rm -rf adityadir
- You will see the directory is deleted
Now become root again and assign sticky bit permission to /allinone = chmod +t /allinone
Become thor user again and try to delete the directory
Although, we’ve assigned all the permissions but still we are not able to delete, it is because of sticky bit.
The Screen Command
Screen command in Linux provides the ability to launch and use multiple shell sessions from a single ssh session. When a process is started with ‘screen’, the process can be detached from session & then can reattach the session at a later time. When the session is detached, the process that was originally started from the screen is still running and managed by the screen itself. The process can then re-attach the session at a later time, and the terminals are still there, the way it was left.
Commands-
screen
-screen -r
-
The Terminal Multiplex Command
The tmux
command in Linux is used to create, manage, and switch between multiple terminal sessions. It's short for "Terminal Multiplexer".
Commands-
tmux
-CTRL+B
&SHIFT+%
- It will divide the screen side by side and for switching the screens useCTRL+B
&arrows keys
-CTRL+B
&SHIFT+"
-To open horizontal tabCTRL+B
&D
- It will detach you form the sessiontmux ls
- To check for all sessionstmux a
- It will take you back to previous statetmux new -s aditya
- To open the session with proper nameCTRL+B & C
- To open new session with the same nameCTRL+B & N
- To traverse between those sessionsCTRL+D
- To permanently remove the sessionCTRL+B & ,
- To rename the sessiontmux kill-session -t 0
= to kill the tmux session
Thanks for going through this blog, Happy Learning !! 😁