10 Basic Commands to Keep Your Linux Secure



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):

Bash
sudo apt install ufw

To check the status:

Bash
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:

Bash
sudo apt install chkrootkit

Then run it:

Bash
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:

Bash
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:

Bash
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.

/etc/motd: Use at for one-time tasks.

Do you enjoy the content we share?

Want to help improve our blog?
You're invited to fill out this form.

Fill Out the Form
QR Form

Scan to open form