Understanding Advanced Linux Concepts and Tools for DevOps Engineers
DevOps and system administration, mastering advanced Linux concepts is crucial. This article delves into essential topics such as user and group management, file permissions, SSH, SCP, systemctl, and the powerful tools grep
, awk
, sed
, and find
. These tools and concepts are indispensable for effective system management and automation.
User and Group Management
Users and Groups:
Users: In Linux, a user is an entity that can execute commands and own files. Each user has a unique ID.
Groups: Groups are collections of users. By assigning permissions to groups, you can simplify the management of file permissions for multiple users.
Real-life Scenario: Imagine you are managing a server for a tech company. You have different teams: developers, QA, and sysadmins. You create users for each member and groups for each team:
sudo useradd soumarghya
sudo usermod -aG developers soumarghya
sudo useradd surendra
sudo usermod -aG sysadmins surendra
Understanding chmod
:
File permissions in Linux are represented by three types of access: read (r), write (w), and execute (x).
Permissions are assigned to three categories: user (owner), group, and others.
Setting Permissions: To set permissions using chmod
, combine values for user, group, and others:
chmod 750 filename
chmod 644 filename
chmod 777 filename
For example, chmod 750
sets permissions to rwx
for the user, r-x
for the group, and ---
for others.
SCP: SCP (Secure Copy Protocol) is used to securely transfer files between hosts on a network using SSH.
scp file.txt soumarghya@server_ip_address:/path/to/destination
Systemctl
Managing Services with
systemctl
:systemctl
is a command to control the systemd system and service manager. It is used to start, stop, and enable services.sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl enable nginxText Processing Tools:
grep
,awk
,sed
,find
grep: grep
is used for searching plain-text data for lines matching a regular expression.
grep "ERROR" /var/log/syslog
Real-life Use: Searching logs for error messages.
awk: awk
is a scripting language used for manipulating data and generating reports.
awk '/ERROR/ {print $1, $2, $3, $4}' /var/log/syslog
Real-life Use: Extracting and formatting log data.
sed: sed
is a stream editor used to perform basic text transformations on an input stream.
sed -i 's/localhost/127.0.0.1/g' config.txt
Real-life Use: Automating text replacements in configuration files.
find: find
is a command-line utility that searches for files in a directory hierarchy.
find /var/log -type f -mtime -1
Real-life Use: Locating files modified within the last 24 hours.
Secure Shell (SSH) and Secure Copy Protocol (SCP)
SSH: SSH (Secure Shell) is a protocol for securely accessing remote machines. It uses encryption to provide a secure channel over an unsecured network.
Setting Up SSH with Public/Private Keys:
Generate SSH key pair on local machine:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Copy the public key to the server:
ssh-copy-id soumarghya@server_ip_addressConnect to the server:
ssh soumarghya@server_ip_address
Subscribe to my newsletter
Read articles from bodhiswatwa chowdhury directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by