33

I'm trying to force a newly created user to change a password at the first time login using ssh. For security reasons I want to give him a secure password until he logs in for the first time. I did the following so far:

useradd -s /bin/bash -m -d /home/foo foo
passwd foo

Doing chage -d 0 foo only gives me the the error Your account has expired; please contact your system administrator on ssh login.

JohnnyFromBF
  • 3,476
  • 10
  • 32
  • 42

2 Answers2

45

change the age of password to 0 day

syntax chage -d 0 {user-name}

In this case

chage -d0 foo

This works for me over ssh also

Ulrich Schwarz
  • 15,669
  • 4
  • 47
  • 58
Security Beast
  • 892
  • 7
  • 14
15

Depending on the version passwd you can try

  • passwd -f: Forces the user to change password at the next login by expiring the password for name.

  • passwd -e or passwd --expire: Immediately expire an account's password. This in effect can force a user to change his/her password at the user's next login.

kawu
  • 281
  • 1
  • 8
  • passwd -e changes the login shell. – schily Feb 11 '16 at 11:11
  • 2
    `passwd -e` works for me (Linux Mint 17.3) – Joril May 16 '17 at 07:52
  • `passwd -e` works in RHEL 7.0 – Crypteya Apr 23 '19 at 01:22
  • @schily The options for `passwd` vary per distribution. On RHEL, `-e` forces a password change on next login. – jrw32982 Oct 30 '19 at 22:46
  • @jrw32982 it is unfortunate, that the Linux people create options to programs that are in conflict with long existing ones from UNIX. The option -f to expire the password is more than 30 years old already and predates Linux by many years. Even the option -e to change the login shell predates a complete Linux. – schily Oct 31 '19 at 10:24
  • 1
    @jrw32982supportsMonica you're most probably right. On the other hand I can't understand how the UNIX guys could name `-f` an option to **e**xpire the password and `-e` to change the **s**hell instead of the obvious `-e` and `-s` respectively. Viewed from here and now, such decision looks like it was asking for trouble. – Stéphane Gourichon Jan 24 '20 at 18:05