Lock It Down: Linux Security Essentials
Welcome to Part 6 of the Command & Conquer series! Linux is known for its security, but even the most robust systems need a vigilant user. This chapter will teach you how to secure your Linux machine by managing users, permissions, and basic configurations to guard against common threats.
Key Security Topics
1. User Management
Control who can access your system and what they can do.
Create a New User:
Syntax:
sudo adduser <username>
Example:
sudo adduser alice
Delete a User:
Syntax:
sudo deluser <username>
Example:
sudo deluser alice
List All Users:
Syntax:
cat /etc/passwd
Example:
cut -d: -f1 /etc/passwd
(for cleaner output).
2. File Permissions and Ownership
Revisit and reinforce file permissions for security.
Check File Permissions:
Command:
ls -l <file>
Output Example:
-rw-r--r--
.
Restrict Access:
Command:
chmod 600 <file>
Explanation: Read and write for the owner only.
Change Ownership:
Command:
sudo chown <user>:<group> <file>
Example:
sudo chown root:root secrets.txt
.
3. Firewall Management with ufw
A firewall is your first line of defense against unauthorized access.
Enable the Firewall:
- Command:
sudo ufw enable
.
- Command:
Allow Specific Ports:
Command:
sudo ufw allow <port_number>
Example:
sudo ufw allow 22
(for SSH).
View Firewall Status:
- Command:
sudo ufw status
.
- Command:
4. Secure SSH Access
Protect remote connections to your Linux machine.
Disable Root Login:
Edit
/etc/ssh/sshd_config
.Set:
PermitRootLogin no
.
Use SSH Keys Instead of Passwords:
Generate a key pair:
ssh-keygen
.Copy the key to your server:
ssh-copy-id <user>@<server_ip>
.
5. Keep Your System Updated
Outdated packages can be a major vulnerability.
Update and Upgrade:
Command:
sudo apt update && sudo apt upgrade -y
6. Audit System Logs
Regularly check logs for suspicious activity.
View Logs:
- Command:
sudo less /var/log/auth.log
(for authentication logs).
- Command:
Monitor in Real Time:
- Command:
tail -f /var/log/auth.log
.
- Command:
Mini Project: Secure Your Linux Machine
Create a New User:
- Add a user with limited privileges:
sudo adduser testuser
.
- Add a user with limited privileges:
Enable the Firewall:
Run:
sudo ufw enable
.Allow SSH:
sudo ufw allow 22
.
Secure SSH:
Disable root login and restart the SSH service:
sudo systemctl restart sshd
Audit Logs:
Check recent authentication attempts:
sudo grep "Failed password" /var/log/auth.log
Why This Matters
Security is an ongoing process. These commands and practices provide the foundation to protect your Linux system from unauthorized access and vulnerabilities. Stay vigilant, and keep your system secure!
What’s Next?
This concludes the Command & Conquer series. Stay tuned for more deep dives into Linux, cybersecurity, and automation. Stay Null. Stay Void. 🤘