Computer

discover the magic command that every user should know

If we want to make any changes to the system, it is not necessary to log in with administrator permissions, but we can request permission using the application sudo to perform administrative tasks by entering our user’s account to confirm that we are the legitimate users of that account and it is not a third person who has had access to our equipment. We can also use the command his if we need to maintain root privileges over time.

Types of users in Linux

One of the most striking features of Linux is its user control, user control with which we can manage the power of action that users have at all times. Basically, in Linux we can find 2 types of users:

  • root. This user has absolute power and control over the computer and can do and undo as he pleases without any type of limitation beyond his knowledge. This type of user is, if we compare it with Windows, the administrator user, although in Linux we have much more decision-making power than in Windows.
  • User. Normal users are user accounts in which a series of limitations are established based on their needs and priorities, without having the option of carrying out administrative tasks reserved for root accounts. These types of users have limited options when it comes to installing applications or creating directories on the system. However, they can get root permissions to make any changes through the commands sudo either his.

When to use sudo and when to use su

Once we are clear that it is root and what are the possibilities of these accounts and the limitations of user accounts, it is time to talk about the sudo and su commands, commands that allow us to obtain administrator permissions to make changes to the system.

sudo

Normal user accounts have limited ability to install off-system applications. The sudo command allows us to execute a command as root, that is, with full privileges over the system, but without ceasing to be a normal user. We must accompany this word always before any operation.

For example, if we want to install an application, as normal users we cannot carry out this process. But, if we use the sudo command first, we’re going to get root permissions to perform that operation. Once it has been done, we will once again have the limitations associated with a normal user account. Whenever we use the sudo command, we will have to enter the root password.

sudo apt install gparted

If we want to install another application, we will have to precede the command, again, with the word sudo and enter the administrator password.

Their

While sudo allows us to obtain administrator permissions to perform certain administrative tasks such as installing applications, creating users and so on, once the command is executed, we are normal users again. If we have to perform various operations on the computer for which administrator privileges are necessary, and we do not want to add sudo to each command, we will use his and enter the root password.

su

As of now, we have root privileges, so we can make any changes to the system without using sudo. Being the previous example, to install the Gparted application, once we have root permissions, instead of preceding the installation command with the word sudo, we can do it without it.

apt install gparted

When we no longer need root privileges, it is recommended to exit this mode to avoid making any unintentional changes, the command is used exit.

exit

If we want to change the user, the command to use is the following.

su nombrecuentausuario

Disable root account in Linux

If we use a computer with Linux that has different user accounts, it is possible that the root password ends up circulating freely in our environment without realizing it. With this password in the wrong hands, users can make any kind of changes and install applications on the system that are not necessary for everyday use. The solution to this problem, as long as we run that risk, is to disable the root account in Linux.

In this way, without a root account, users will not be able to use either sudo or su to enable administrator privileges in the system, having a positive impact on the security of the work computer. To deactivate the root account, we must open terminal and enter the following command

sudo passwd l root

In this way, the equipment blocks this user so that it cannot be used even with the remote control. his nor with sudo. If we want to recover the user account again, we will have to configure a new one.

Recover root password

Whether we have disabled the root account or if we have lost the master password, Linux allows us to regenerate a new password through two methods: from the boot GRUB or using a LiveCD with a Linux distribution.

with GRUB

Once the bootable GRUB is displayed, we must access the advanced options, an option that is not on the main screen, and then select recovery mode to then select the option root for a superuser console.

From the command line, the first thing we will do is mount the drive with write permissions with the command

mount -o rw, remount /

Next, we will use the command passwd to set a new password

passwd root

Finally, with the commands we use the commands sync Y reboot to restart the computer for the changes to take effect.

sync

[coche]reboot[/code]

From a LiveCD

To recover the root password, we can use any LiveCD distro, although from SoftZone we recommend Ubuntu. Once we have started the computer with this distribution, on the welcome screen, we select Spanish so that the interface is displayed in our language, and then Try Ubuntu.

Next, we open the Terminal application and enter the following command:

sudo su

Next, we must identify the partition where the Linux distribution we want to recover the root password is located. To do this we will use the command:

fdisk -l

In the next step, we need to mount the system unit:

mkdir /mnt/recover
mount /dev/sda1 /mnt/recover

In our case, the partition is sda1. If it is different on our computer, we must modify sda1 for the partition corresponding to our computer. Once we have mounted the unit, we can start working with it to recover the root password. The first thing is to go to the recovery directory with the command:

chroot /mnt/recover

And finally, we use the command passwd to enter a new root password

passwd root

Related Articles