In Linux, user accounts are the primary way to control access to the system. Each user has a unique identifier (UID) and belongs to one or more groups. Permissions are set at the file and directory level, determining who can read, write, or execute a file. The three types of permissions are r
(read), w
(write), and x
(execute), and they can be set for the owner, group, and others.
A firewall is a network security device that monitors and controls incoming and outgoing network traffic based on predetermined security rules. In Linux, iptables
and firewalld
are commonly used firewall management tools. They allow you to block or allow traffic based on IP addresses, ports, and protocols.
Encryption is the process of converting data into a code to prevent unauthorized access. Linux supports various encryption methods, such as file - level encryption using cryptsetup
and network encryption using SSH (Secure Shell).
# Create a new user named "newuser"
useradd newuser
# Set a password for the new user
passwd newuser
# Give read, write, and execute permissions to the owner of a file named "testfile"
chmod u+rwx testfile
# Give read and execute permissions to the group and others
chmod go+rx testfile
iptables
# Flush all existing rules
iptables -F
# Allow incoming SSH traffic (port 22)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow outgoing traffic
iptables -A OUTPUT -j ACCEPT
# Drop all other incoming traffic
iptables -A INPUT -j DROP
firewalld
# Start the firewalld service
systemctl start firewalld
# Enable the firewalld service to start on boot
systemctl enable firewalld
# Allow SSH service
firewall - cmd --permanent --add - service=ssh
# Reload the firewall rules
firewall - cmd --reload
cryptsetup
# Create a new encrypted partition
cryptsetup luksFormat /dev/sdb1
# Open the encrypted partition
cryptsetup open /dev/sdb1 myencryptedpartition
# Create a file system on the opened partition
mkfs.ext4 /dev/mapper/myencryptedpartition
# Mount the partition
mount /dev/mapper/myencryptedpartition /mnt/encrypted
# Generate SSH key pair
ssh - keygen -t rsa
# Copy the public key to the remote server
ssh - copy - id user@remote_server
# Connect to the remote server using SSH
ssh user@remote_server
# Update the package list
apt update # For Debian - based systems
yum update # For Red Hat - based systems
# Upgrade installed packages
apt upgrade # For Debian - based systems
yum upgrade # For Red Hat - based systems
# List all running services
systemctl list - units --type=service
# Stop and disable a service, for example, "httpd"
systemctl stop httpd
systemctl disable httpd
# View the system log
tail -f /var/log/syslog # For Debian - based systems
tail -f /var/log/messages # For Red Hat - based systems
Enforce password complexity rules using tools like pwquality
in Linux. Edit the /etc/security/pwquality.conf
file to set requirements such as minimum length, number of digits, and special characters.
Only grant users the minimum amount of access necessary to perform their tasks. For example, a regular user should not have root privileges unless absolutely required.
Use tools like rsync
to create regular backups of important data.
# Backup the "documents" directory to an external drive
rsync -avz /home/user/documents /media/externaldrive/backup
Securing your Linux system using the command line is a crucial skill for system administrators and users. By understanding fundamental concepts such as user accounts, permissions, firewalls, and encryption, and by following usage methods, common practices, and best practices, you can significantly enhance the security of your system. Regularly updating your system, monitoring logs, and implementing strong security policies will help protect your system from various threats.