Home > Learn > Server > Guide to Changing Passwords in Ubuntu Linux
Understanding Ubuntu Password Storage
When transitioning from a Windows server to an Ubuntu environment, understanding how passwords are stored and managed is crucial. Ubuntu, like other Linux distributions, uses a specific system for securely storing user account information and password hashes.
This article is part of Rackset’s Server guides — browse the rest of the category for more in-depth tutorials on this topic.
Where Are Ubuntu Passwords Located?
In Ubuntu, user account information is primarily stored in two files:
/etc/passwd: This file contains essential information about user accounts, such as the username, user ID (UID), group ID (GID), home directory, and shell. It is readable by all users, but it does not contain password hashes for security reasons./etc/shadow: This file holds encrypted password hashes and is accessible only by the root user or users with elevated permissions. This separation enhances security by restricting access to sensitive password data.
Understanding the /etc/passwd File
The /etc/passwd file is a plain text file with each line representing a single user account. The fields in each line are separated by colons (:) and include:
username:password:UID:GID:comment:home_directory:shell
For example:
moe:x:1001:1001:Moe User:/home/moe:/bin/bash
In this example, the password field is represented by an ‘x’, indicating that the actual password hash is stored in the /etc/shadow file.
Understanding the /etc/shadow File
The /etc/shadow file is more secure as it contains the encrypted password hashes. Each line corresponds to a user in the /etc/passwd file, with fields separated by colons:
username:password_hash:last_change:min:max:warn:inactive:expire
An example entry might look like this:
moe:$6$randomsalt$hashedpassword:18517:0:99999:7:::
Here, the password hash is stored in the second field, which is generated using a cryptographic hash function with a salt to enhance security.
Security Considerations
It’s essential to understand that direct editing of these files should be avoided to prevent system issues. Instead, use command-line tools like passwd, usermod, or chpasswd to manage passwords securely and efficiently.
Accessing the Terminal in Ubuntu
If you’ve recently switched from a Windows server to Ubuntu, you might find yourself unfamiliar with some basic operations, such as accessing the terminal. The terminal is a powerful tool in Ubuntu, allowing you to execute commands and perform tasks that aren’t always possible through the graphical interface.
Launching the Terminal
There are several ways to open the terminal in Ubuntu. Here are some of the most common methods:
- Keyboard Shortcut: The quickest way to open the terminal is by pressing Ctrl + Alt + T on your keyboard. This shortcut works in most versions of Ubuntu.
- Search Function: Click on the “Activities” button in the top-left corner of your screen or press the Super key (often the Windows key on your keyboard). Type “Terminal” in the search bar and click on the Terminal icon that appears.
- Application Menu: You can also find the terminal in the application menu. Click on the grid icon in the bottom-left corner of the screen to open the application menu, then scroll through the list or search for “Terminal.”
Understanding the Terminal
Once you’ve opened the terminal, you’ll see a command-line interface where you can type commands. The terminal allows you to perform tasks such as updating your system, installing software, and managing files. For instance, you can change user passwords, including the root password, using specific commands.
Read more: How to Change Root Password on CentOS
If you need this service, Rackset’s team provides professional Linux VPS with full support so you can rely on the quality and get set up quickly.
Basic Terminal Commands
Here are a few basic commands to get you started with the terminal:
| Command | Description |
|---|---|
ls |
Lists files and directories in the current directory. |
cd |
Changes the current directory. |
pwd |
Prints the current working directory. |
sudo |
Executes a command with administrative privileges. |
With these basics, you’re ready to start using the terminal to manage your Ubuntu system, including changing user passwords as described in the previous sections.
Changing a User’s Password
Changing a user’s password in Ubuntu is a straightforward process that can be accomplished using the terminal. This is particularly useful if you have recently switched from a Windows server environment to Ubuntu and need to manage user credentials efficiently. Below, we outline the steps to change a user’s password, including the root password, using terminal commands.
Changing Another User’s Password
If you need to change the password for another user on your system, you will require administrative privileges. This can be done using the sudo passwd command followed by the username. For instance, to change the password for a user named Moe, execute the following command:
sudo passwd Moe
You will be prompted to enter a new password for Moe. Ensure that the password is strong and secure to maintain account safety.
Changing the Root Password
The root account in Ubuntu is a powerful user account with full administrative rights. Changing the root password is a critical task that should be done with caution. To change the root password, use the following command:
sudo passwd root
After executing this command, you will be prompted to enter a new password for the root user. Make sure to use a complex password to enhance security.
Changing Your Own Password
If you need to change your own password, you can do so without administrative privileges by using the passwd command. Simply type the following command in the terminal:
passwd
You will be asked to enter your current password, followed by the new password. This method is user-friendly and allows you to update your password without affecting other users.
Best Practices for Password Management
- Always use a combination of letters, numbers, and special characters to create strong passwords.
- Avoid using easily guessable passwords such as “123456” or “password”.
- Change passwords regularly to mitigate security risks.
- Consider using a password manager to keep track of your credentials securely.
By following these steps, you can effectively manage user passwords in Ubuntu, ensuring both security and ease of access.
Changing the Root Password
Changing the root password in Ubuntu is a crucial task, especially if you’ve recently switched from a Windows server to an Ubuntu environment. The root user has unrestricted access to the system, so it’s important to secure it with a strong password. Follow the steps below to change the root password effectively.
Prerequisites
- Ensure you have administrative privileges on the Ubuntu system.
- Access the terminal, which you can open by pressing
Ctrl+Alt+T.
Steps to Change the Root Password
- Open the terminal on your Ubuntu system.
- To change the root password, enter the following command:
sudo passwd rootThis command will prompt you to enter your current user password to authorize the change.
Read more: Changing Passwords on a Linux VPS Server: A Guide
For projects that need guaranteed resources and full root control, a VPS is the right step up from shared hosting. With VPS hosting you get dedicated CPU/RAM, NVMe storage, a dedicated IP and high uptime, deployed in minutes.
- After authorization, you will be prompted to enter a new password for the root user. Make sure to choose a strong password that includes a mix of uppercase, lowercase, numbers, and special characters.
- Re-enter the new password to confirm it.
- If the passwords match, you will receive a confirmation message indicating that the password has been updated successfully.
Important Considerations
- Ensure that the root password is kept secure and only shared with trusted administrators.
- Regularly update the root password to enhance security.
- Consider disabling root login over SSH to prevent unauthorized access.
Troubleshooting
If you encounter any issues while changing the root password, ensure that you have entered the current user password correctly when prompted. Additionally, verify that your user has the necessary sudo privileges to execute the command.
Removing a User’s Password
In certain scenarios, you might need to remove a user’s password in Ubuntu. This could be necessary for creating a passwordless account for specific use cases, such as automated scripts or when setting up a system that doesn’t require user authentication. Removing a password from a user account can be accomplished using the terminal.
Using the passwd Command
The passwd command can be used to remove a user’s password by setting it to a blank state. This action should be performed with caution, as it will allow the user to log in without a password. To remove a password for a user named Moe, execute the following command:
sudo passwd -d Moe
This command deletes the user’s password, effectively allowing them to log in without any password prompt.
Using the usermod Command
Alternatively, you can use the usermod command to achieve the same result. The usermod command is a versatile tool for modifying user account properties. To remove a password for a user named Moe, use:
sudo usermod -p '' Moe
This command sets the encrypted password to an empty string, removing the need for a password upon login.
Security Considerations
While removing a user’s password might be useful in certain situations, it is crucial to consider the security implications. Accounts without passwords can pose significant security risks, especially if they have elevated privileges or access to sensitive information.
- Ensure that the account is used in a secure environment where unauthorized access is not a concern.
- Consider using SSH keys or other secure authentication methods if remote access is required.
- Regularly review user accounts and their access levels to maintain a secure system.
Re-adding a Password
If you need to re-add a password to a user account, you can use the passwd command again. For example, to set a new password for user Moe, run:
sudo passwd Moe
Follow the prompts to enter and confirm the new password. This will re-enable password protection for the user account.
Setting Password Expiration
Setting password expiration policies is a crucial aspect of user account management, especially in a server environment like Ubuntu Linux. It ensures that users regularly update their passwords, enhancing security by reducing the risk of unauthorized access. In this section, we will explore how to set password expiration for user accounts in Ubuntu.
Understanding Password Expiration
Ubuntu uses the /etc/shadow file to store password expiration details. Each user account in this file has several fields, including those related to password aging. The fields are:
Read more: How to Change DocumentRoot in DirectAdmin
- Last Password Change: The number of days since the password was last changed.
- Minimum Age: The minimum number of days before a password can be changed.
- Maximum Age: The maximum number of days a password is valid before it must be changed.
- Warning Period: The number of days before expiration that the user is warned to change their password.
Setting Password Expiration Policies
To configure password expiration, you can use the chage command. Below are steps to set expiration policies for a user named Moe:
For heavy workloads and maximum performance, a dedicated bare-metal server gives you an entire physical machine. Rackset’s dedicated server deliver full hardware, root access and configurable port speeds for the most demanding sites and apps.
- Open the terminal by pressing
Ctrl+Alt+T. - To set the maximum age of the password to 90 days, execute:
sudo chage -M 90 Moe - To set a warning period of 7 days before password expiration, use:
sudo chage -W 7 Moe - To set the minimum age to 7 days, preventing immediate changes, enter:
sudo chage -m 7 Moe - To view the current password aging settings for Moe, type:
sudo chage -l Moe
Automating Password Expiration for New Users
You can automate password expiration settings for all new users by editing the /etc/login.defs file. Look for the following parameters and modify them as needed:
PASS_MAX_DAYS: Maximum number of days a password is valid.PASS_MIN_DAYS: Minimum number of days between password changes.PASS_WARN_AGE: Number of days warning before a password expires.
For example, to set a global maximum age of 90 days, minimum age of 7 days, and a warning period of 7 days, you would adjust the file as follows:
PASS_MAX_DAYS 90
PASS_MIN_DAYS 7
PASS_WARN_AGE 7
By setting these parameters, you ensure that all new user accounts adhere to your organization’s password policies, improving overall security.
Additional Tips & Common Mistakes
Additional Tips
Changing passwords in Ubuntu is a straightforward process, but there are additional tips that can help you manage passwords more effectively:
- Use Strong Passwords: Ensure that passwords are strong and include a mix of uppercase and lowercase letters, numbers, and special characters. This helps protect your system from unauthorized access.
- Regular Updates: Regularly update your passwords to enhance security. Setting a reminder to change passwords every three to six months is a good practice.
- Utilize Password Managers: Consider using a password manager to securely store and manage your passwords. This can help you generate strong passwords and avoid using the same password across multiple accounts.
- Backup Important Data: Before making any changes to user accounts or passwords, ensure you have backups of important data to prevent data loss in case of any issues.
- Check Password Expiry: Use the
chagecommand to check and set password expiry dates for users, ensuring that all passwords are periodically updated.
Common Mistakes
When changing passwords in Ubuntu, be aware of these common mistakes to avoid potential issues:
- Forgetting to Use ‘sudo’: If you are not logged in as the root user, remember to use
sudobefore thepasswdcommand when changing passwords for other users or the root account. - Incorrect Username: Double-check the username when changing passwords for other users. A typo can result in an error or affect the wrong account.
- Not Confirming Password Change: Always ensure that the password change was successful by logging out and logging back in with the new credentials.
- Ignoring Password Complexity: Simple passwords can be easily compromised. Always adhere to complexity requirements to enhance security.
- Changing Root Password Unnecessarily: Only change the root password if absolutely necessary, as frequent changes can lead to confusion and potential lockouts.
Example Command for Checking Password Expiry
chage -l username
Replace username with the actual username to view the password expiry information. This can help you manage password updates more effectively.
Practical Step-by-Step Examples
Changing a User Password in Ubuntu
When you need to change a password in Ubuntu, you can easily do so using the terminal. This is particularly useful if you’ve switched from a Windows server to Ubuntu and are accustomed to using graphical interfaces. Here’s how you can achieve this:
Changing Another User’s Password
- Open the terminal by pressing
Ctrl+Alt+T. - To change the password for a user named Moe, enter the following command:
sudo passwd Moe - You will be prompted to enter your sudo password for authentication.
- Once authenticated, you will be prompted to enter a new password for the user Moe. Enter the new password and confirm it when prompted.
Changing Your Own Password
- Open the terminal by pressing
Ctrl+Alt+T. - Simply type the following command and press Enter:
passwd - You will be prompted to enter your current password.
- After successful authentication, enter your new password and confirm it when prompted.
Changing the Root Password in Ubuntu
Changing the root password is a similar process, but it requires administrative privileges. Follow these steps:
- Open the terminal by pressing
Ctrl+Alt+T. - To change the root password, type the following command:
sudo passwd root - Enter your current sudo password to authenticate.
- You will then be prompted to enter a new password for the root user. Enter and confirm the new password.
These commands will help you efficiently manage user passwords in your Ubuntu system, whether you’re updating your own password, managing other users, or securing the root account. Always ensure that passwords are strong and meet security standards to protect your system effectively.
Secure Your Ubuntu Experience
Unlock seamless password management and enhanced security with Rackset’s Linux VPS. Enjoy the flexibility and peace of mind knowing your server is as secure as your passwords.
Elevate your Ubuntu security today!
Conclusion
Changing passwords in Ubuntu Linux is a straightforward process that enhances the security of your system. By following the steps outlined in this guide, you can efficiently update your passwords to protect your user accounts from unauthorized access. Whether you are changing a password for a single user or managing multiple accounts, Ubuntu provides the tools you need to maintain robust security practices. Regularly updating your passwords and using strong, unique combinations are essential steps in safeguarding your data.
As you continue to explore the capabilities of Ubuntu Linux, remember that security is an ongoing process. Stay informed about best practices and consider automating some of your security tasks to save time and reduce errors. If you’re looking for reliable hosting solutions that prioritize security and performance, consider Rackset for your web hosting needs. Our team is committed to providing you with the tools and support necessary to keep your systems secure and efficient.
Frequently Asked Questions
How do I change my password in Ubuntu Linux?
To change your password in Ubuntu Linux, open a terminal and type `passwd`. Follow the prompts to enter your current password and then your new password twice for confirmation.
What should I do if I forget my Ubuntu password?
If you forget your Ubuntu password, you can reset it by rebooting into recovery mode. From there, drop to a root shell prompt and use the `passwd` command to set a new password.
Can I change another user’s password in Ubuntu?
Yes, you can change another user’s password in Ubuntu by using the command `sudo passwd username`, replacing ‘username’ with the actual username. You will need administrative privileges to do this.
Is it possible to change passwords without knowing the current one?
Administrators can change passwords without knowing the current one by using `sudo passwd username`. Regular users must know their current password to change it.
How often should I change my Ubuntu password for security?
For optimal security, it’s recommended to change your Ubuntu password every 3 to 6 months. Additionally, use a strong password with a mix of letters, numbers, and symbols.

Leave a Reply