How to Find the PID of a Linux Process With pidof or pgrep
Working with a Linux process often means knowing its process ID, or PID. It’s a unique number given to each piece of running software.
[mai mult...]How to List Linux Services With systemctl
Services and daemons are background tasks that run without a user interface, don’t require human interaction, and are usually started as the computer boots up.
At one time, services were launched by init
, which was the very first process to be launched. The details of the services were held in a collection of scripts located in the “/etc/init/d” directory. On non-systemd distributions that’s still the case.
In the systemd world, services are launched by systemd
which is the now first process to be launched. The details of the services are stored in unit files located in the “/usr/lib/systemd” directory.
According to its man page, systemd
is a system and service manager. You can use the systemctl
command to inspect and control different aspects of the systemd system, including services and daemons.
Because we’re looking at systemd-specific commands here, the first thing you need to know is whether you’re running a systemd-based distribution or not.
[mai mult...]9 Useful Examples of the Linux rsync Command
- The rsync Tool
The rsync
tool copies files and directories between two computers. It uses a sophisticated algorithm that scans directory trees to find files on the source computer that don’t exist on the destination computer. These files are transmitted to the destination computer. What makes rync
so clever is it can figure out which pieces of existing files have been modified, and it only sends the changed portions.
You can use rsync
to copy files to a different location on your hard drive, to a different hard drive in the same computer, to an externally connected USB drive, or any other network-accessible location.
On top of that, rsync
can optionally preserve symbolic links, hard links, and file metadata such as file ownership, permissions, and access times. To support all this functionality, rsync
has many options and figuring them all out takes time. We’ve collected these 10 examples to help you get started. We’ve already written about doing backups with rsync
, so we’re concentrating on other uses here.
For all of its many options, the structure of an rsync
command is simple. We need to provide the source, the destination, and the options we want to use. You’ll probably find that rsync
is already installed on your Linux computer—it was, on all of our test machines—but if it isn’t it’ll definitely be in your distribution’s repositories.
How to Add a User to the sudoers File in Linux
The people who can use the Linux sudo
command are members of a small and select club, sometimes called the “sudoers” list. Each member has the same powers as root
. So how do you join that club? We’ll walk through adding a person to sudoers as well as editing the sudoers file to limit permissions.
How to List Environment Variables on Linux
On Linux, environment variables hold important values and settings. Scripts, applications, and shells read these values, often to configure themselves, or to control their behavior. Here are several ways to show those variables in your terminal.
[mai mult...]How to Integrate Applications and Scripts to a Linux Desktop
How to Kill a Linux Process by Port Number
How (and Why) to Disable Root Login Over SSH on Linux
You need someone with the authority to own and administer those parts of your operating system that are too important or too sensitive for regular users to deal with. That’s where root comes in. root is the all-powerful superuser of Unix and Linux operating systems.
The root user account, like all accounts, is protected by a password. Without the root user’s password, no one else can access that account. That means root’s privileges and powers cannot be used by anyone else. The flip side is that the only defense between a malicious user and root’s powers is that password. Passwords, of course, can be guessed, deduced, spotted written down somewhere, or brute-forced.
If a malicious attacker discovers root’s password they can log in and do anything they like to the entire system. With root’s elevated privileges there are no restrictions on what they can do. It would be just as if the root user had walked away from a terminal without logging out, allowing opportunistic access to their account.
Because of these risks, many modern Linux distributions don’t allow root to login to the computer locally, never mind over SSH. The root user exists, but they don’t have a password set for them. And yet, someone has to be able to administer the system. The solution to that conundrum is the sudo
command.
sudo
allows nominated users to temporarily use root-level privileges from within their own user account. You need to authenticate to use sudo
, which you do by entering your own password. This gives you temporary access to root’s capabilities.
Your root powers die when you close the terminal window they were used in. If you leave the terminal window open they’ll timeout, automatically returning you to regular user status. This provides another type of protection. It protects you from yourself.
If you habitually log in as root instead of a regular account, any mistakes you make on the command line could be catastrophic. Having to use sudo
to perform administration means you’re more likely to be focused and careful about what you type. Allowing root login over SSH increases the risks because attackers don’t have to be local; they can try to brute-force your system remotely.