Using sudo for Temporary Root Privileges
For users with sudo privileges, you can execute commands as root without needing to log in directly as the root user. This method enhances security by using your user password instead of the root password. For example, to list the contents of the /root directory, you can run:sudo -i and sudo --login achieve the same result:
Using sudo for temporary privileges helps minimize the security risks associated with prolonged root sessions.
Using su to Log In as Root
If your user does not have sudo privileges but you know the root password, you can switch to the root account using thesu command. The following command is commonly used:
Handling Locked Root Accounts
Some systems lock the root account by default to improve security. A locked root account disables password-based logins, but it does not prevent access to the root shell if you have sudo privileges.Enabling Password-Based Root Login
If you prefer to enable password-based logins for the root account, consider the following two scenarios: • If the root account never had a password set, assign a new one.• If the root account had a password that was later locked, you can unlock it using one of these commands:
Enabling password-based logins can be useful for specific administrative tasks but consider the security implications carefully.
Locking the Root Account
Conversely, if you decide that permitting password-based logins for the root account is too risky, you can lock the account by running:Make sure to verify that your user account has the necessary sudo privileges before locking the root account. Otherwise, you risk losing critical administrative access.