How to Change User Password in Linux

Техника

Note: We have tested the commands described here on Ubuntu 20.04 LTS. However, the same commands also work for other Linux distributions.

Содержание
  1. Change User Password through Command Line
  2. Change Your Own Password
  3. Change Password for Another User
  4. Change Root Password
  5. Force a User To Change Its Passwords
  6. Change Password through GUI
  7. Introduction
  8. How to Change Another User’s Password in Linux
  9. Change a User’s Password Without a Prompt (Non-Interactive)
  10. Change Passwords for Multiple Users
  11. How to Force a User to Change Password at Next Login in Linux
  12. Locking & Unlocking User Passwords in Linux
  13. Conclusion
  14. Change user password in Ubuntu [Command Line]
  15. Change (or set) the root password in Ubuntu
  16. Change Ubuntu password using GUI
  17. More on user passwords in Linux
  18. Reset Ubuntu password from recovery mode
  19. Step 1: Boot into recovery mode
  20. Step 2: Drop to root shell prompt
  21. Step 3: Remount the root with write access
  22. Step 4: Reset username or password
  23. Possible Troubleshoot:
  24. Alternate method to reset Ubuntu password
  25. Step 1
  26. Step 2
  27. Step 3
  28. Step 4
  29. If resetting Ubuntu passwords is this easy, isn’t this a security risk?
  30. Bonus Tip: Handling the possible keyring issue after changing the password
  31. Did it help you?
  32. Prerequisites
  33. Passwd command Options
  34. Passwd Command Examples
  35. Change User Password
  36. Immediate password expiry 
  37. Check password status for user 
  38. Delete user password 
  39. Set inactive days after the password expiry 
  40. Set minimum days to change the password
  41. Set warning period before password expiry
  42. Set maximum days password remains valid
  43. Lock a user account
  44. Unlock a user account
  45. Enable quiet mode
  46. Change Password in Bash
  47. Conclusion
  48. Linux passwd Command
  49. Selecting Strong Password
  50. Change Your Own or Current User Password
  51. Change Another/Different User Password
  52. Change Password From GUI
  53. Change Password For GNOME
  54. Change Password For XFCE
  55. Force Password Change In Next Login
  56. Linux User and Password Files
  57. Introduction
  58. Temporary Switching to root
  59. Changing Root Password
  60. Conclusion
  61. Without Rebooting
  62. Reboot Required
  63. Other Ways
Дополнительно:  Синий экран смерти 0x000000FE: устранение Stop-ошибки на

Change User Password through Command Line

Change Your Own Password

To change your own password, simply type the below command without sudo in your terminal window:

$ passwd

After doing so, your password will be changed.

Change Password for Another User

$ sudo passwd <username>
$ sudo password sim

Change Root Password

$ sudo passwd
$ sudo passwd root

First, provide the password for sudo, and then enter the new password that you want to set for the root account.

After doing so, the password of the root account will be changed.

Force a User To Change Its Passwords

$ passwd --expire <username>
$ passwd --expire sim

Change Password through GUI

Step 1: Open Settings application in your system. You can do so right-clicking the desktop and choosing Settings from the appeared menu. Alternatively, you can press the super key and in the search area, type settings. Then from the search results, select the Settings utility.

Karim Buzdar

These commands should work on any Linux distribution, such as Ubuntu, Debian, Linux Mint, CentOS, Rocky Linux, etc.

Introduction

In Linux and Unix-like operating systems, you can change passwords, and related changes, using the passwd utility. The hashed passwords, along with other related information is stored in the /etc/shadow file. To see the file contents you can go ahead and run:

sudo cat /etc/shadow

It’s very important that you keep a habit of using strong passwords on your machines. This is especially important if your machine is a server that’s exposed to the internet, where bad actors may constantly attempt to break in.

Table of Contents
  1. Introduction
  2. How to Change Your User Password in Linux
  3. How to Change Another User’s Password in Linux
  4. How to Force a User to Change Password at Next Login in Linux
  5. Locking & Unlocking User Passwords in Linux
  6. Conclusion
passwd

You’ll be prompted to enter your current password to make sure it’s really you.

Changing password for edxd.
Current password:

Input your current password and press Enter.

Дополнительно:  Ноутбук не видит телевизор через HDMI - почему не подключается и нет сигнала. Ремонт в СПб

Passwords won’t be displayed on the screen when you input them, for security reasons.

If the password you entered is correct, you’ll next you’ll be prompted to type the new password you want to set.

Usually, the minimum requirements for your new password are a minimum length of 6 characters, for the password not to be too simple, and for it not to be too similar to the current password.

We recommend you use a complex password of at least 12 characters, as we mentioned in the intro.

New password:

Next you’ll have to enter the new password again:

Retype new password:

If the password fits the minimum requirements then your password should now be successfully changed, and the next time the system asks it will expect your new password.

passwd: password updated successfully

How to Change Another User’s Password in Linux

sudo passwd bytexd_user
New password:
Retype new password:
passwd: password updated successfully
passwd: You may not view or modify password information for bytexd_user.

Change a User’s Password Without a Prompt (Non-Interactive)

sudo usermod --password $(openssl passwd -6 '8n&E8MgZd^Rc') bytexd_user

It’s recommended that you put the password in single quotes – '8n&E8MgZd^Rc' instead of 8n&E8MgZd^Rc, in order to avoid accidental character substitution if you have characters such as $1 in your password.

Change Passwords for Multiple Users

First we run the command:

sudo chpasswd
edxd:somenewpassword
bytexd_user:someothernewpassword
stelixd:yetanotherpassword

When you are done press Ctrl+D for the changes to take effect and return to the regular prompt.

There won’t be any confirmation message in the output.

How to Force a User to Change Password at Next Login in Linux

sudo passwd -e bytexd_user
passwd: password expiry information changed.
ssh [email protected]
You are required to change your password immediately (administrator enforced)
Changing password for bytexd_user.
Current password:
New password:
Retype new password:
passwd: password updated successfully
Connection to 172.141.197.192 closed.

After successfully updating the password, if you’re logging in via SSH, then the connection will close.

Дополнительно:  Наличие прав root что это

Locking & Unlocking User Passwords in Linux

We can do this using passwd -l.

sudo passwd -l bytexd_user
passwd: password expiry information changed.
[email protected]'s password:
Permission denied, please try again.
sudo passwd -u bytexd_user
passwd: password expiry information changed.

Conclusion

You can view all options for the passwd command from the manual by running man passwd in your command line, or by reading the man page online.

If you have any questions or have enountered issues, feel free to leave a comment and we’ll get back to you as soon as we can.

Why do you need to change the password in Ubuntu? Let me give you a couple of scenarios.

  • Change user password via the command line
  • Change root user password
  • Change user password via GUI

Change user password in Ubuntu [Command Line]

If you want to change your current password, simply run this command in a terminal:

passwd

You’ll be asked to enter your current password and the new password twice.

You won’t see anything on the screen while typing the password. This is perfectly normal behavior for UNIX and Linux.

Change password of the current user using "passwd" command
Change Password using passwd

Sometimes, the passwd command will throw errors like:
Small Password: If the new password is shorter than 8 characters
Fails Dictionary Check: Does not contain enough different characters. So, use some other characters than just numbers and try again.

sudo passwd <user_name>
Change the password of another user in Ubuntu terminal
Change another user password

If you changed your password and forgot it later, don’t worry. You can easily reset Ubuntu password.

How to Reset Forgotten Ubuntu Password in 2 Minutes

Change (or set) the root password in Ubuntu

You can set or change root password using the passwd command. However, in most cases, you don’t need it and you shouldn’t be doing it.

Now, about changing the root password.

Else, you can change it using the existing root password.

sudo passwd root
Change root password using "passwd" command
Change Root Password

Change Ubuntu password using GUI

I have used GNOME desktop with Ubuntu 22.04 here. The steps should be more or less the same for other desktop environments and Ubuntu versions.

Go to Overview (press Windows/Super key) and search for Settings.

Go to Users in Ubuntu GNOME settings and Unlock the section using the current logged in user password
Select Users and Unlock it
Changing user password in Ubuntu
Change Password of the User

Now, select Set password Now option on the dialog box and type and confirm the new password. If you are changing your own password, you’ll also have to enter your current password.

Changing the current user password in Ubuntu needs to type the existing password also
Enter Current user password also

How to Reset Forgotten Ubuntu Password in 2 Minutes

More on user passwords in Linux

Passwd command in Linux: 8 Practical Examples

Here’s a fun thing you can do with sudo so that it makes fun of you when you enter incorrect password.

And get familiar with the Seahorse password manager app in Linux desktops.

Seahorse: Manage Your Passwords & Encryption Keys in Linux


Forgot your Ubuntu login password? It happens.

If you haven’t used Ubuntu for some time, it’s only natural to not remember the password. The good news is that you don’t need to reinstall the entire operating system because of it. You can recover Ubuntu passwords easily.

The method mentioned here works for resetting an Ubuntu password in VMware, dual boot or single install. All you need is a little bit of patience and to run a couple of commands. You’ll reset the root password within minutes.

Forgot Linux Password on WSL? Here’s How to Reset it Easily

Forgot the password of your Linux distribution app you installed in Windows via WSL? No worries. You can easily reset the Linux password in WSL.

Reset Ubuntu password from recovery mode

Step 1: Boot into recovery mode

Switch the computer on. Go to the grub menu. Generally, it appears automatically – if not, then hold down the shift key or press Esc key until the boot menu appears.

If you’re using Oracle VirtualBox or VMware, you have to hold down the shift key when the logo of Oracle or VMware appears.

In the grub menu, select the “Advanced Options for Ubuntu”:

Advanced boot options in Grub menu of Ubuntu
This is grub screen

In here, you’ll see the option to go to recovery mode:

Boot into recovery mode

It will bring you to a black screen with several lines of output being displayed in a flash. Wait for a few seconds here.

Step 2: Drop to root shell prompt

Now you’ll be presented with different options for recovery mode. Here you need to choose “Root – Drop to root shell prompt“.  Just press the enter key to select this option. Like in the picture below:

Root shell prompt allows you to reset password in Ubuntu

You’ll see that when you select the root shell prompt option, an option to enter commands appears at the bottom. This is your root shell prompt and this is where you’ll use the commands to reset the password.

Step 3: Remount the root with write access

You need to have write access to the root partition. By default, it has read-only access.

Use the command below to remount it with write access:

mount -rw -o remount /

Step 4: Reset username or password

ls /home
passwd username

It prompts for a new password. Enter the new password twice.

Do note that nothing is displayed on the screen when you start typing the password. This is perfectly normal and actually a security feature in Linux systems. Just blindly type the password and press enter.

Enter new UNIX password:
Retype new UNIX password:

Voilà! There you go. You have just successfully reset the password. Now exit the root shell prompt:

exit

When you exit, you’ll be back at the recovery mode menu. Select the normal boot option here.

Use recovery mode to boot normal after resetting password in Ubuntu

There will be a warning about graphics mode compatibility. Don’t worry. A complete reboot will fix any issues with this.

You should now be able to log in with the new password.

Possible Troubleshoot:

While entering the new password you might be prompted with Authentication token manipulation error like this:

mount -rw -o remount /

Now try to reset the password again. It should work now.

As you can see, it is extremely easy to change Ubuntu password even if you’ve forgotten it. It will barely take a few minutes.

Alternate method to reset Ubuntu password

If for some reason you have difficulty dropping to the root shell and changing the password, you can try these steps.

Step 1

Reboot your computer. Hold shift to bring up the grub screen (if it doesn’t appear automatically). Press E at the grub prompt to edit the grub screen.

Step 2

Find the line starting with linux, change the ro to rw and append init=/bin/bash at the end of that line.

Editing grub to fix frozen boot issue with Ubuntu Linux
Change ro to rw and add init=/bin/bash at the end of this line

Step 3

Press ctrl-x to save your changes and boot.

In other words, your system will boot up to a passwordless root shell.

Step 4

Set your new password.

Once you’ve set the new password, exit the terminal. Just type reboot in the terminal or use the shutdown command.

shutdown -r now

Your password should be changed now.

If resetting Ubuntu passwords is this easy, isn’t this a security risk?

That’s a fair question. One of the main advantages of Linux over Windows is its security. But if “anyone” can reset the password, how come Ubuntu or other Linux distributions can be considered secure?

Let me explain a few things here. The main security risk is if someone hacks into your account from a remote location via the internet. That’s not happening here.

If anyone has physical access to your computer, the data in your computer is already at risk. Unless the entire disk is encrypted, anyone can “steal” your data using a live USB without even entering your installed operating system.

This lack of root password is a deliberate feature The “advanced options for Ubuntu” in the boot menu allow you to perform some specific root-related tasks from the “root shell prompt”. This is why you’re able to reset the Ubuntu password through this method.

Bonus Tip: Handling the possible keyring issue after changing the password

There is a keyring feature in Ubuntu that is used for keeping passwords locked and safe.

When you reset the forgotten password, the keyring remains unlocked and you may see an error message like this.

Enter Password To Unlock Your Login Keyring Ubuntu

Open the Passwords and Keys application and here, delete the Login passwords.

Delete Keyring Ubuntu
Delete Keyring Ubuntu

When you try to use Google Chrome again in Ubuntu, it will ask you to create a new keyring. Use the new login password as the keyring password.

Did it help you?

Donate Itsfoss

I hope I made things clear about resetting forgotten passwords in Ubuntu.


In this tutorial, we’ll be learning about passwd command in Linux to change passwords in Linux. 

Prerequisites

  • Any Linux system
  • Basic knowledge of Linux command line
  • An existing user account
  • Required privilege to run the command
passwd [option] [user]

The configuration files passwd uses are:

  • /etc/passwd — stores the user account information
  • /etc/shadow — stores secure user account information
  • /etc/pam.d/passwd — stores PAM configuration for passwd

Passwd command Options

Passwd Command Examples

Change User Password

Type passwd command without any option can change your own password.

$ passwd

To change the root password, type:

sudo passwd root
change root password

Immediate password expiry 

$ sudo passwd -e werewolf
change user password immediately

As we can see, we are provided with the message that the password expiry information changed.

$ su werewolf
prompt user to change password

Check password status for user 

check password status

Understanding password status output:

  • The user linuxopsys has a usable password (P) that is set to expire on 02/08/2022.
  • The user has to wait minimum 0 days between password changes i.e. can change password without any set interval.
  • The user has to change his password every 99999 days.
  • User will be warned 7 days before a required password change.
  • The number of days after which the user’s account will be disabled following the password expiry is set to -1 i.e. user account won’t be disabled after the password expiry.
$ sudo passwd -Sa
all users password status

Delete user password 

$ sudo passwd -d werewolf
delete user password
verify no password login

Set inactive days after the password expiry 

$ sudo passwd -i 7 werewolf
set account inactive

You can verify by typing: 

$ sudo passwd -S werewolf

Set minimum days to change the password

$ sudo passwd -n 1 werewolf
minimum days to change password

Set warning period before password expiry

$ sudo passwd -w 5 werewolf
days in advance warning about password expiry

The number of warning days has changed to 5 in the password status:

verify by checking password status

Set maximum days password remains valid

$ sudo passwd -x 7 werewolf
set maximum days password remain valid

Confirm by checking:

Lock a user account

$ sudo passwd -l werewolf

Unlock a user account

sudo passwd -u werewolf 
check unlocked user account

Enable quiet mode

$ passwd -q
enable quiet mode

Change Password in Bash

echo -e "newpassword" | passwd username

Conclusion

In this tutorial, we became familiar with the passwd command which is used to change passwords. We have also covered some of the useful passwd command options with practical examples.

Linux passwd Command

passwd OPTIONS USERNAME

OPTIONS is used to specify different options like delete, expire, inactivate password.

Help and more information about the passwd command can be printed by using the -h or –help option like below.

$ passwd -h

Selecting Strong Password

!W2i0s2e0tut._
  • Use both upper and lower case letters multiple times randomly
  • Use digits from 0 to 9 multiple times randomly
  • Use special characters and punctuation marks like !,*?#$%;. etc.
  • Do not use regular daily words without change
  • Make it easy to remember but can not be guessed by others especially attackers

Change Your Own or Current User Password

$ passwd
Change Current User Password
$ whoami

Change Another/Different User Password

$ sudo passwd ahmet
$ sudo passwd root
$ su -
Password: 
# 
# passwd
New password: 
Retype new password: 
passwd: password updated successfully

Change Password From GUI

Change Password For GNOME

Change Password For GNOME
Change Password For GNOME

Change Password For XFCE

Change Password For XFCE
Change Password For XFCE

Force Password Change In Next Login

$ sudo passwd --expire ismail

Linux User and Password Files

$ cat /etc/passwd
/etc/passwd File
$ cat /etc/shadow
cat: /etc/shadow: Permission denied
$ 
$ sudo cat /etc/shadow

Introduction

Temporary Switching to root

sudo command-name
sudo su -
whoami
Output

root

Changing Root Password

sudo passwd root

The new root password will be required to be entered and confirmed.

Make sure you use a strong and unique password when creating the password. The most critical part of your account’s security is having a strong password. A strong password often consists of at least 16 characters, one uppercase letter, one lowercase letter, one number, and one special character.

When you type the password, it does not appear on the screen.

Output

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

That’s it. The password for the root account has been updated.

You can now use the new password to log in to your Ubuntu system as root.

Conclusion

The root account in Ubuntu has no password by default. To run commands with root capabilities, the sudo command is advised.

You’ll need to set the root password before you can log in as root.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Here are a few ways I can think of, from the least intrusive to the most intrusive.

Without Rebooting

With sudo: if you have sudo permissions to run passwd, you can do:

sudo passwd root

Enter your password, then enter a new password for root twice. Done.

These are the easy ones.

Reboot Required

  1. Reboot.
  2. Enter boot-time password, if any.
  3. Enter your boot loader’s menu.
  4. If single user mode is available, select that (Debian calls it ‘Recovery mode’).
  5. If not, and you run GRUB:
    1. Highlight your normal boot option.
    2. Press e to enter edit mode. You may be asked for a GRUB password there.
    3. Highlight the line starting with kernel or linux.
    4. Press e.
    5. Add the word ‘single’ at the end. (don’t forget to prepend a space!)
    6. Press Enter and boot the edited stanza. Some GRUBs use CtrlX, some use b. It says which one it is at the bottom of the screen.
mount / -o remount,rw
passwd # Enter your new password twice at the prompts
mount / -o remount,ro
sync # some people sync multiple times. Do what pleases you.
reboot

and reboot, or, if you know your normal runlevel, say telinit 2 (or whatever it is).

  1. Mount the root volume.
  2. Get passwd running.
  3. Change your password with the passwd command.

Rescue Disk: this one’s easy. Boot a rescue disk of your choice. Mount your root filesystem. The process depends on how your volumes are layered, but eventually boils down to:

 # do some stuff to make your root volume available.
 # The rescue disk may, or may not do it automatically.
 mkdir /tmp/my-root
 mount /dev/$SOME_ROOT_DEV /tmp/my-root
 $EDITOR /tmp/my-root/etc/shadow
 # Follow the `/etc/shadow` editing instructions near the top
 cd /
 umount /tmp/my-root
 reboot

Other Ways

Obviously, there are countless variations to the above. They all boil down to two steps:

  1. Get root access to the computer (catch-22 — and the real trick)
  2. Change root’s password somehow.

I want to change the password I assigned to root on my Debian webserver to something longer and more secure.

How do I do that? I haven’t forgotten/lost the current password, I just want to change it.

Rui F Ribeiro's user avatar

Rui F Ribeiro

26 gold badges146 silver badges225 bronze badges

asked Mar 25, 2011 at 14:08

Paul D. Waite's user avatar

Paul D. WaitePaul D. Waite

5 gold badges21 silver badges21 bronze badges

Ah, use the passwd program as root:

sudo passwd root

Or, if you’re running as root already (which you shouldn’t be), just:

passwd

Community's user avatar

answered Mar 25, 2011 at 14:08

Paul D. Waite's user avatar

Paul D. WaitePaul D. Waite

5 gold badges21 silver badges21 bronze badges

answered Mar 25, 2011 at 20:30

Phil Lello's user avatar

You have to boot in Recovery Mode before using Paul D. Waite’s suggestion:

  1. Right after booting your Debian system choose «boot in Recovery Mode»
  2. Right after booting into «Recovery Mode» right at the command prompt simply
    type:

    sudo password root
    

    then the system will ask for the new Root’s password once and twice to verify and you ARE done.

Anthon's user avatar

42 gold badges164 silver badges222 bronze badges

answered Sep 16, 2014 at 5:12

Juan Blanco's user avatar

I’m trying to change the password that is asked when running sudo in Ubuntu. Running sudo passwd or sudo passwd root does give me the two new password prompts and it successfully changes the password.

So the root password is changed but not the password for sudo.

How do I change the sudo password?

Anthony Geoghegan's user avatar

asked Feb 25, 2013 at 18:35

user1494552's user avatar

To change it, try plain passwd, without arguments or running it through sudo.

Alternately, you can issue:

$ sudo passwd <your username>

answered Feb 25, 2013 at 18:37

Frédéric Hamidi's user avatar

The password you use for sudo is the password of your own account, not the root account. sudo is used to grant you access to commands that need to be executed as root without giving you root access directly. To change your own password, use passwd without sudo.

answered Feb 25, 2013 at 18:37

Femaref's user avatar

Оцените статью
Master Hi-technology
Добавить комментарий