How to change a password in Linux: A step-by-step guide to securing your system

In the world of computing, security is essential, and passwords are the first line of defense. This is particularly true in Linux systems, where password management is key to ensuring a secure environment. While passwordless SSH connections can be a viable alternative, at the end of the day, a strong password remains the best option to protect your server.

This article provides a detailed guide on how to change passwords in Linux, covering popular distributions like Ubuntu, Debian, and RedHat Enterprise, Suse Linux, CentOS (AlmaLinux, CloudLinux and RockyLinux). Whether you want to change your own password or manage those of other users, this tutorial will help you master the necessary commands to handle passwords in a Linux environment.

How to Change a Password in Linux

Changing a password in Linux is simple and only requires one basic command. Before getting started, you need to access your server via SSH. If you need assistance, there are many tools available such as PuTTY, SecureCRT or browser-based terminals offered by some hosting services.

  1. Access your server via SSH.
  2. Run the following command in the terminal: sudo passwd

This command will prompt you to enter a new password twice to confirm the change. The process will look like this in your terminal:

Enter new UNIX password:
Retype new UNIX password:

Once you’ve successfully entered the new password, you’ll see a confirmation message like this:

passwd: password updated successfully

This means your new password has been successfully updated, and the old one is no longer valid.

How to Change Another User’s Password in Linux

If you have root access or superuser privileges, you can also change the passwords of other users on the system. The process is similar to changing your own password, but with a slight variation in the command:

  1. Log in as root or use sudo.
  2. Enter the following command, replacing “username” with the actual username of the account whose password you want to change:bashCopiar códigopasswd username

For example, if you want to change the password for a user named stackscale, the command would be:

passwd stackscale

Just like before, you will be prompted to enter the new password twice:

Enter new UNIX password:
Retype new UNIX password:

And just like that, you’ve successfully updated the password for another user using the passwd command.

Passwords and Linux

Linux is known for its high level of security, but like any other operating system, it relies heavily on passwords to protect users and their data. There are two key files related to password management in Linux:

  1. /etc/passwd: This file contains basic information about all system users, such as usernames and group affiliations. However, not all accounts listed here are authorized to log in. You can view the contents of this file with the following command: cat /etc/passwd
  2. /etc/shadow: This file is more critical as it contains the encrypted passwords of users and other sensitive information, such as SSH key usage. Access to this file is restricted to users with elevated privileges: cat /etc/shadow

How to Create a Secure Password

Changing your password frequently is not enough if the passwords you choose aren’t strong. Here are some tips for creating a robust password:

  • Unique and long: Use a combination of uppercase and lowercase letters, numbers, and special characters, and ensure your password is at least 12 characters long.
  • Avoid personal information: Don’t use pet names, birthdays, nicknames, or other easily guessable information.
  • Don’t reuse passwords: Each important account should have its own unique password to prevent a security breach from affecting multiple accounts.
  • Update them regularly: Change your passwords frequently to minimize the risk of them being compromised.

If you suspect your password has been compromised, change it immediately.

The security of Linux systems largely depends on proper password management. Changing a password is a simple process that can be completed with just a few commands, but its impact on system security is crucial. Keeping your passwords updated and secure is the best practice for protecting your project, whether personal or professional. In short, prevention is key to avoiding future problems. Always stay safe in the digital world!

Scroll to Top