Linux Training : Section 5 (Part-2)

Module 5 - System Administration

Process Management

  • Background = cntl+z, jobs and bg

  • Foreground = fg

  • Run process even after exit = nohup process & OR nohup 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 processes

    • df - report file system disk space usage

    • dmesg - print or control the kernel ring buffer

    • iostat - 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 information

    • cat /proc/meminfo - memory information

Logs Monitoring

  • Log Directory- /var/log…Important files under this directory-

    • boot

    • chronyd = NTP

    • cron

    • maillog

    • secure

    • messages

    • httpd

System Maintenance Commands

  • Commands-

    • shutdown = Shutdown the system

    • init = Service manager

    • reboot = Reboot the system

    • halt = 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 line

  • CTRL+C - stop/kill a cmd

  • CTRL+Z - suspend a cmd

  • CTRL+D - exit from an interactive program (signals end of data)

Terminal Commands-

  • clear - clears your screen

  • exit - exit out of the shell, terminal or a user session

  • script - 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-

  1. Restart your computer

  2. Edit grub

  3. Change Password

  4. 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 OR env

    • 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-

  1. 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/shadow

  2. setgid: bit tells Linux to run a program with the effective group id of the owner instead if the executor(e.g., locate or wall command)

    NOTE: setuid and setgid is not the actual cmd to set, we will use chmod command.

  3. 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:

  1. Become root and create a directory allinone in / = mkdir /allinone

  2. Assign all rwx permissions to that directory = chmod 777 /allinone/

  3. Become aditya and create directory inside of /allinone = mkdir adityadir

  4. Give all rwx permissions to that directory = chmod 777 adityadir

  5. Create 3 files in that directory = touch a b c

  6. Open another terminal and login as thor

  7. Go to /allinaone directory and delete adityadir directory = rm -rf adityadir

    • You will see the directory is deleted
  8. Now become root again and assign sticky bit permission to /allinone = chmod +t /allinone

  9. 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-

  1. screen-

  2. 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-

  1. tmux -

  2. CTRL+B & SHIFT+% - It will divide the screen side by side and for switching the screens use CTRL+B & arrows keys-

  3. CTRL+B & SHIFT+" -To open horizontal tab

  4. CTRL+B & D - It will detach you form the session

  5. tmux ls - To check for all sessions

  6. tmux a - It will take you back to previous state

  7. tmux new -s aditya - To open the session with proper name

  8. CTRL+B & C - To open new session with the same name

  9. CTRL+B & N - To traverse between those sessions

  10. CTRL+D - To permanently remove the session

  11. CTRL+B & , - To rename the session

  12. tmux kill-session -t 0 = to kill the tmux session

Thanks for going through this blog, Happy Learning !! 😁