10 Basic Commands to Keep Your Linux Secure

Are you new to Linux or have been using it for a while but never really got into the topic of security? Well, if there’s something I learned the hard way, it’s that it doesn’t matter how “secure” Linux is compared to other operating systems, if you leave the door open yourself, problems come in on their own.
The good news about all this: you donât need to be an expert or a hacker. With just a few simple commands, you can check, adjust, and strengthen your system without complications.
Here are 10 basic commands to keep your Linux system secure, explained clearly and directly.
1. sudo apt update && sudo apt upgrade
Letâs start with the basics. Keeping your system updated is the main thing, but also the most important.
This command updates packages and applies security patches. Many attacks take advantage of known bugs that were fixed years ago, but if you never update…
Tip: Do it often, or at least once a week.
2. ufw enable
With this command, you activate your systemâs firewall (if you have UFW installed). Itâs like putting a fence around your house. (A little more security.)
To install it (if you donât have it):
sudo apt install ufw
To check the status:
sudo ufw status
Pro tip: Enabling it doesnât block everything. Linux already comes with secure default rules.
3. sudo apt autoremove && sudo apt autoclean
This isnât directly about security, but it’s always good. It helps you clean old packages that are no longer in use and could pose a risk if they stay unpatched.
Less junk, fewer problems or places to attack.
4. chkrootkit
This command helps you detect if your system has a rootkit (a type of malware that embeds deep in the system).
Install it like this:
sudo apt install chkrootkit
Then run it:
sudo chkrootkit
Itâs not foolproof, but itâs a good precaution and way to stay alert.
5. sudo lastlog
This shows the last time each user logged in.
Why does this matter? Because if you see that the user âpedroâ logged in yesterday and you didnât even know that user existed, you have a serious problem.
It helps detect strange or unauthorized access.
6. sudo fail2ban-client status
If you use Fail2Ban (and you should), this command lets you check if itâs working properly.
Fail2Ban is a program that blocks IPs that try to log in with the wrong passwords too many times. Itâs essential for servers or PCs exposed to the internet.
To install it:
sudo apt install fail2ban
Once configured, this command shows what itâs doing.

7. sudo netstat -tulnp
This command shows which ports are open and which programs are using them. (Itâs always good to check a bit.)
Itâs great for spotting services that shouldnât be running. For example, if you see something that says â:6667â and you have no idea what it isâlook it up.
Modern alternative:
sudo ss -tulnp
8. ls -l /etc/passwd /etc/shadow
This lets you see the permissions of the system’s password files. They should be accessible only to root.
If you see something weird like âeveryone can read /etc/shadowâ, you have a serious security hole.
9. who
Simple and directâit shows who is currently logged in.
Should it just be you and no one else? Perfect.
Is someone else connected and you donât know who it is? Investigate immediately.
10. sudo crontab -l
This shows the scheduled tasks for the root user.
Why does it matter? Because an attacker can leave scheduled commands to run automatically. If you see something you didnât set, check it now. (Itâs always good to investigate a bit.)
Extra Tip: Use Timeshift
This isnât a command, but if you use Linux Mint (or another compatible distro), install Timeshift. It lets you make system backups and restore if something breaks or you get infected. (It can save you from a problem.)

In summary:
You donât have to become paranoid, but donât be overconfident either. With these commands, you can control what happens on your system and spot weird things before itâs too late.
Itâs not about fearâitâs about common sense. (About precaution.)
And youâdo you already use any of these commands? Are you missing any in your routine? Tell me in the comments.
Do you enjoy the content we share?
Want to help improve our blog?
You're invited to fill out this form.

Scan to open form