28

I have been using this server for a few months. At the beginning I sent the admin my public ssh key, and he set up the account for me, and I have only used the ssh key to log in. I definitely didn't have a password at first.

Since then I may or may not have set up a password using passwd. Right now if I use passwd I see this.

$ passwd
Changing password for user myusername.
Changing password for myusername.
(current) UNIX password:

While it seems to suggest that I do have a password, I have no memory of ever doing this.

How can I tell conclusively whether my password is set?

EDIT:
I can't log in nor change password, because I don't know what the password is (blank password doesn't work). The distro is Fedora release 20 (Heisenbug).

6
  • Try to log in without password (and without your ssh private key of course).
    – didierc
    Commented Feb 15, 2015 at 16:24
  • I can't log in because I don't know the password, and blank doesn't work. I added this info in the original question. Commented Feb 15, 2015 at 16:46
  • 1
    On a login console, a blank password is the same as no password.
    – didierc
    Commented Feb 15, 2015 at 16:59
  • 1
    You'll get this password prompt even if there's no password configured for the account. If no password is configured, passwd will complain of a wrong password no matter what you type. Commented Feb 15, 2015 at 22:27
  • I've verified that on a vanilla Fedora 20 using local shadow passwords, passwd will not ask for your current password if you do not have one. Another way to check is to type su myusername; if there's no password, it will not ask for one. But any of this can be overridden by the system administrator, for example by removing the nullok option from the pam_unix entries in /etc/pam.d/*, in which case a non-administrator cannot tell who has passwords and who does not, except perhaps by doing timing tests. Commented Feb 16, 2015 at 16:13

4 Answers 4

43

The best way is with the following command:

passwd --status username

From man passwd:

Display account status information. The status information consists of 7 fields. The first field is the user's login name. The second field indicates if the user account has a locked password (L), has no password (NP), or has a usable password (P). The third field gives the date of the last password change. The next four fields are the minimum age, maximum age, warning period, and inactivity period for the password. These ages are expressed in days.

So, if the second output field is NP, then, that user has no password set.

7
  • I got $ passwd --status Only root can do that. Commented Feb 15, 2015 at 16:43
  • In this case, try sudo passwd username --status.
    – jherran
    Commented Feb 15, 2015 at 16:45
  • I got $ sudo passwd myusername --status [sudo] password for myusername: but since I don't know my password, I can't continue. Commented Feb 15, 2015 at 16:48
  • I tested my original command and should work fine with a newly created user without special perms: $ passwd --status test returns test P 02/15/2015 0 99999 7 -1.
    – jherran
    Commented Feb 15, 2015 at 17:09
  • Weird. I am wondering if the admin has set it up in a non-standard way. Commented Feb 15, 2015 at 17:21
4

You can test this in 2 easy ways.

  1. Right after you change the password, as root type login, that will bring you to a login/password prompt.

  2. Depending on your system odds are you are using shadow passwords. The file for that is in /etc/shawdow you can look in that file to see if your account has any changes to it.

Here is an example with an account without a passwrod set:

postgres: :16462:0:99999:7:::

Here is what it might look like for a user with a password:

dustin:$6$TQ8e8o92$T9KWfcEVeIpDytW/zSAZzM4512wd/DiiuaYwrYWheH3LYpOsISdRxrCLvPqJZZ66QqdetmaV0ALQohx8nQPFKK0:16425:0:99999:7:::

Notice between the : : is the encrypted password and for the postgres account it had nothing

5
  • For #1, I can't change password, because I don't know what the password is. If I put in a blank, it says passwd: Authentication token manipulation error. For #2, I don't have /etc/shawdow. There is a /etc/shadow, but the permission is 000. (not sure if this matters) I forgot to mention that I have Fedora release 20 (Heisenbug). Probably should have put these information in the original question. Commented Feb 15, 2015 at 16:38
  • Your token error tends to come from wrong permissions. Are you in Single usermode ? When you booted was it a normal boot? Also to check type just "mount" you want to make sure every thing is mounted as rw (read and write) Commented Feb 15, 2015 at 17:11
  • Also that is a wrong permission, what distro is this? Commented Feb 15, 2015 at 17:13
  • I don't think the server is in single user mode. I can still log in using ssh credentials, and I can see other users with who. Everything listed in mount is listed as rw. Distro is Fedora release 20 (Heisenbug). Commented Feb 15, 2015 at 17:35
  • If one has a ! as result, then this answer can help which explains that the user is locked.
    – Timo
    Commented May 8, 2020 at 5:10
1

Try using the following:

passwd -S

From passwd(1) man page we read:

-S Report password status on the named account. The first part indicates if the user account is locked (LK), has no password (NP), or has an existing or locked password (PS). The second part gives the date of the last password change. The next parts are the minimum age, maximum age, warning period, and inactivity period for the password.

0

You may want to see the /etc/passwd file. The second field on your user indicates the password. If nothing is there you may have no password for your login. On the other hand, if you have an x on this field you have a password associated to it and it may be at the /etc/shadow file

2
  • Thanks! There is an x. I guess I do have a password. There is no /etc/shadow file though. Commented Feb 15, 2015 at 16:45
  • 1
    @ceilingcat If you see an x, that doesn't tell you anything about whether a password is set. You need to look in /etc/shadow (which requires being root). Commented Feb 15, 2015 at 22:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .