Best Practices for Linux System Administration: Beginner to Intermediate
Hi there, Are you new to Linux system administration or have been maintaining systems for some time? I hope this collection of basic Linux commands will help you manage your system from your command line.
Note: Linux is a huge asset in the IT world, powering your webservers to your cloud infrastructures!
Powering most of our web servers, mobile phones, personal computers, supercomputers, and cloud servers. Now it would be so frustrating for a system administrator if they had to manually manage updates, troubleshooting, and running all the time.
Now, to become an administrator, you need to have an understanding of Linux system administration, which will take care of multiple tasks & responsibilities such as network environment, managing, monitoring CPU usage, configuring, and maintaining Linux operating systems.
Before I begin, let us understand some basic concepts and know the responsibilities for a system administrator:
1. What is Linux Administration?
2. What Should a Linux Administrator Know?
3. What Are the Duties of a Liunx Administrator?
4. Basic Practices for the Linux System Administrator?
What is Linux Administration?
Linux administration is about setting up disaster recovery, managing new system builds, creating backups to restore data, Linux hardware management, managing storage, handling file systems, and managing the security of Linux systems. A big part of Linux administration is ensuring that Linux-powered systems are stable and secure.
What Should a Linux Administrator Know?
Linux system administrators are expected to handle Linux file systems, manage the root user, have a working knowledge of bash commands, and an ability to manage users.
What Are the Duties of a System Administrator in Linux?
1. Maintenance of a Linux environment.
2. Troubleshooting and providing support when there’s an issue with Linux servers.
3. Analysis of log files (mainly error logs).
4. Support of LAN and web applications.
5. Creation of operational and project-specific solutions for the organization.
6. Ability to proactively figure out ways to enforce strong security practices and increase scalability of your Linux environment.
Basic Practices for the Linux System Administrator?
· Logging and Monitoring Centralized.
· Patch management and routine security audits.
· Automation of Backups and Disaster Recovery Strategies.
· Strengthen SSH Security and Privileged Access Control by Optimizing the sudoers file
· Optimizing and rebuilding the kernels.
· Using Kubernetes and Docker for containerization.
· Monitoring of Advanced System Resources.
· Implementing automation.
· Network performance tuning for effective disk management with LVM and RAID.
· Keeping Up Extensive Records.
Basic Configuration
In this article we are going to make use of some Linux commands for Linux System Administrators that are used daily.
1. User and Group Management
Adding and Managing Users
User management is a fundamental aspect of system administration. Users are added using the “useradd” command, and their account details are stored in “/etc/passwd” and “/etc/shadow”. Assigning users to appropriate groups is essential to control their access to system resources effectively.
Steps to Creating a New User
Open your terminal and run this command
sudo useradd -m -s /bin/bash janesmith
sudo passwd janesmith
Creating a New Group
sudo groupadd avengers #the name you desire
Modify a Group
sudo groupmod avengers
Managing Permissions
Permissions in Linux are set at three levels: owner, group, and others. These permissions control who can read, write, or execute files and directories. As an administrator, it’s vital to ensure that permissions are set correctly to protect sensitive data.
Steps to managing permissions
Open your terminal and run this command
chmod 750 /var/www/html
chown -R janesmith:www-data /var/www/html
2. Package Management
Linux distributions use package managers to handle software installation, updates, and removal. Understanding the package manager for your distribution (e.g., ‘apt’ for Debian/Ubuntu, ‘yum’/’dnf’ for CentOS/RHEL) is essential for maintaining software and system security
Steps to install Software in your Linux System
Open your terminal and run this command
#If you are on Debian/Ubuntu
sudo apt update
sudo apt install nginx
# CentOS/RHEL
sudo yum update
3. Security and Monitoring
Securing Linux Systems
Security is a top priority in Linux system administration. Implement measures such as setting up firewalls, configuring SELinux or AppArmor, and managing SSH access to protect the system from unauthorized access and attacks.
Steps to configuring a firewall with “ufw (Unsolicited Firewall)”
Open your terminal and run this command:
sudo ufw allow ssh
sudo ufw allow http
sudo ufw enable
Monitoring System Performance
Monitoring tools like “top”, “htop”, “netstat”, and “vmstat” help you keep track of system performance, identify bottlenecks, and ensure that resources are used efficiently.
#Display real-time system resource usage
sudo top
#Reports virtual memory statistics
sudo vmstat
#Monitors network connections both incoming and outgoing
sudo netstat
#Displays the running process of CPU and memory
sudo htop
Log Management
Linux systems generate logs that record events and errors. As an administrator, regularly checking and managing these logs is essential to detect and address issues early. Logs are typically stored in “/var/log/.”.
#View the system log
sudo tail -f /var/log/syslog
Automation and Scripting
Using Shell Scripts
Automation through scripting is a key skill for Linux system administrators. Shell scripts allow you to automate repetitive tasks, such as backups, user management, and system updates, enhancing efficiency and reducing the potential for human error.
How to run Simple Backup Script
#!/bin/bash
tar -czf /backup/home_$(date +%F).tar.gz /home
4. Networking Commands
Networking commands play an important role in system administration, and a good system administrator must have good hands-on networking commands. Networking commands display the diagnosis of your network on your system.
Network Administration Commands
# Test connectivity to a host
ping google.com
# Traces the route of a host
traceroute google.com
#Displays socket statistics
ss -tuln
#configures wireless network interfaces
Iwconfig wlan0
These are best practices that Linux system administrators can use to ensure that their Linux systems are safe, effective, and prepared for any future issues.
- Logging and Monitoring Centralized
For a perfect Linux System Administration, you can try implementing tools for centralized logging, what it does is it allows log management centralization and lets you access all of your logs in one place, which can speed up and simplify the log data search.
The log data repository allows you to easily search for pertinent occurrences rather than having to guess which server contains the right file. There are three main protocols you can choose from when transmitting log data: UDP, TCP, and RELP.
For large management solutions, centralization is essential since it makes troubleshooting and production issue resolution easier by enabling log analysis, parsing, and indexing before keeping them in one place.
Log Management Tools to Use:
Cons
Still being a superior choice, centralized log management carries some risks, such as data loss and excessive network traffic. But don’t worry there are more clever Linux system Administration solutions following this.
2. Patch Management and Routine Security Audits
Verify vulnerabilities by conducting security audits. Apply security updates and patches regularly to keep your system safe from attacks. Establish a routine for updates to prevent forgetting.
Attackers attempt to target as many machines as they can as soon as they can since they are aware that they only have a brief window of opportunity before machines are patched. Usually, the attackers carry out these attacks on holidays in the hopes that most system administrators won’t be able to patch their machines. Every newly hacked machine joins the assaulting force automatically as these attacks are carried out.
Any program may contain a security flaw. For example, there were significant security flaws in Java, Adobe Reader, Adobe Flash, and Oracle that required patching.
Tip: Install all program and OS fixes as soon as they are released.
3. Automation of Backups and Disaster Recovery Strategies
Another Linux system administration strategy is to automate backup solutions for data integrity.
While mirrors or RAIDs do not guard against fire, theft, or security breaches, backups offer recovery in the event of a compromised machine, a failed disk, or hardware failure.
You can plan a disaster recovery keeping the following things in mind:
· Make sure you regularly back up your Linux file system.
· It is possible to plan these backups to run at suitable intervals.
· When executing a disaster recovery, make sure the destination client and the source client are the same.
· Installing the Linux operating system on the machine you wish to repair should be the top goal. Ensure that the operating system is installed exactly as it was before a hardware or software corruption issue occurred.
· The Linux File System iDataAgent needs to be installed on the client computer’s default install partition.
· Ensure that the networking option is enabled.
· The default install’s hostname, domain name, and TCP/IP settings need to match the restored system’s settings.
· To restore a system, create and mount a root file system on it.
4. Strengthen SSH Security and privilege Access Control by Optimizing the sudoers file.
It may be often underestimated but ensuring Secure SSH (Secure Shell) is extremely important for Linux System Administration when dealing with remote servers. Why is it so essential?
SSH is a target for brute attacks, so hardening SSH configuration is a safety precaution for advanced Linux administration.
Think about totally shutting down incoming SSH connections.
SSH can be used to tunnel other protocols, like X windows and FTP, to execute commands remotely and access shells remotely. As with all network services, it should be turned off when not in use.
You should disable root login; here’s how you can do it:
- Open the configuration file for SSH
sudo nano /etc/ssh/sshd_config
2. Find the PermitRootLogin line and set its value to no:
PermitRootLogin no
3. To apply changes, restart SSH
sudo systemctl restart sshd
Additional practices for SSH security are:
· Using SSH Keys instead of passwords as they’re cryptographic key pairs (Private & Public Keys)
· Usually used via SSH, port 22 is a popular target for automated attacks. By making it more difficult for hackers to find your SSH service, changing this port improves security.
· Then, two-factor authentication for SSH access. To set it up on Linux, the tools recommended are Google Authenticator or Duo Security.
· IPs that have been attempting incorrect passwords should have their connections closed. Block the IP addresses indefinitely.
· Firewalls: To regulate incoming and outgoing traffic, use firewalls or IPtables.
Implementing this security will secure your Linux system administration.
5. Optimizing and Rebuilding the Kernels
Hardening Linux Kernels and optimizing them is the core of the Linux System Administration, controlling system functions, security, and hardware resources. To maintain system stability, security, and performance, any Linux system administrator must optimize and harden the kernel.
While kernel optimization focuses on enhancing performance by fine-tuning system parameters, kernel hardening entails installing security configurations and technologies that shield the kernel from infections and attackers.
Use these strategies for Kernel hardening & optimization:
Implementing this security will secure your Linux system administration.
5. Optimizing and Rebuilding the Kernels
Hardening Linux Kernels and optimizing them is the core of the Linux System Administration, controlling system functions, security, and hardware resources. To maintain system stability, security, and performance, any Linux system administrator must optimize and harden the kernel.
While kernel optimization focuses on enhancing performance by fine-tuning system parameters, kernel hardening entails installing security configurations and technologies that shield the kernel from infections and attackers.
Use these strategies for Kernel hardening & optimization
These tools limit the access that processes have to system resources, adding degree of protection. To implement stringent access control procedures and lessen any security risks, use AppArmor or SELinux.
Control Modules in the Kernel
Empty kernel modules can be exploited and, therefore load just what is required. Enabling module signing and blacklisting superfluous modules contribute to system security.
Turn on Kernel Address Space Layout Randomization (KASLR):
By generating random memory addresses, KASLR makes it more difficult for attackers to target the kernel.
System Parameter Optimization
To modify memory management and network performance, use the sysctl command. Depending on your workload, you may be able to enhance performance by modifying the swappiness and TCP settings.
sudo sysctl -w net.core.rmem_max=16777216
sudo sysctl -w net.core.wmem_max=16777216
sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
sudo sysctl -w net.ipv4.tcp_wmem="4096 65536 16777216"
Adjust the swappiness value
sudo sysctl -w vm.swappiness=10
Now create a new file in /etc/sysctl.conf with these changes to make them permanent.
5. Turn Off Unused Features
If not in use, disable unused filesystems and protocols like IPv6. This lowers resource consumption and minimizes the attack surface.
6. Consistent Kernel Updates
Update the kernel is necessary to implement security updates and boost performance. For crucial upgrades that don’t require downtime, think about live patching.
You can update the kernel on Debian and Ubuntu systems by using:
sudo apt-get update
sudo apt-get upgrade
If you are using RHEL/CentOS:
sudo yum update
Using Kubernetes and Docker for Containerization
You should integrate Kubernetes and Docker in your Linux System administration for containerization.
Docker is a framework for containerization that bundles programs into uniform containers for simple deployment and environment-neutral operation. This is great for Linux administrators, ensuring better resource utilization and simple application management.
The container orchestration platform Kubernetes offers capabilities including rolling updates, self-healing, autoscaling, and interaction with GCP services. It is used to manage and automate containerized applications. reduces the need for manual intervention by managing rolling updates, load balancing, and self-healing.
Installing Docker or Kubernetes on your computer or server is the first step towards using them for containerization. You will also need to set up a cluster for Kubernetes. You can use images from Docker Hub or another container registry to construct containers once they are installed. It’s also possible to make your unique pictures.
7. Monitoring of Advanced System Resources
The effectiveness of monitoring system resources for Linux System Administration should not be underestimated. This is a crucial practice Linux administrators follow. With Linux’s extensive toolkit, system administrators may efficiently monitor and control system performance.
For proactive system management and troubleshooting in this dynamic environment, it is essential to comprehend and make use of these monitoring commands and tools.
I’ll tell you a few very useful commands & tools for Linux system administration to monitor system resources:
free Command
· This command displays memory usage statistics and avoids memory depletion.
· It shows data about memory usage in Linux.
free
The iostat command
· Helps detect possible problems such as high disk use or sluggish performance; it provides comprehensive statistics on disk input and output operations as well as CPU utilization.
iostat
8. Implementing Automation
Another useful practice for Linux system administration is to automate your server tasks. Scripts and technology for automation can be used to speed up boring administrative tasks. Log rotation, user management, and software deployment are examples of regular processes that can be automated.
Automation reduces human error, boosts productivity, and frees time for other crucial tasks. To guarantee consistency in server deployments and installations, use configuration management tools like Ansible or Puppet.
9. Network performance tuning for effective disk management with LVM and RAID
Network performance tuning is a very crucial aspect of Linux system administration; it focuses on the interaction between disk performance and network resources. Administrators can improve system dependability and efficiency.
Try leveraging RAID (Redundant Array of Independent Disks) for data redundancy and LVM (Logical Volume Manager) for flexible storage management.
Strategies Used by Linux Administrators
· Improve the way networks are configured.
· Put Quality of Service (QoS) into practice for important data flows.
· To find bottlenecks, employ performance monitoring technologies.
· Guarantee stable system operation, streamlined data flow, responsive apps, and enhanced user experience.
10. Keeping Up Extensive Records
Maintain complete records of documentation of all of your setups, modifications, and procedures. For troubleshooting and orienting new team members, this is quite helpful.
Subscribe to my newsletter today!
If you like my work and want me to keep you updated with this, you can buy me a coffee.
Ready to dive deeper into the world of technology?
LinkedIn: Connect with me to stay updated on tech-related insights. Let’s network and collaborate on exciting projects.
X: Join me on X for tech news and engaging discussions. Follow me, and let’s share our thoughts in the X verse. Follow on X.
Substack: Subscribe to my Substack and stay up-to-date with the latest news in cybersecurity, Web3.