34

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.

2 Answers 2

46

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

16

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.

6
  • passwd -e changes the login shell.
    – schily
    Commented Feb 11, 2016 at 11:11
  • 2
    passwd -e works for me (Linux Mint 17.3)
    – Joril
    Commented May 16, 2017 at 7:52
  • passwd -e works in RHEL 7.0
    – Crypteya
    Commented Apr 23, 2019 at 1:22
  • @schily The options for passwd vary per distribution. On RHEL, -e forces a password change on next login.
    – jrw32982
    Commented Oct 30, 2019 at 22:46
  • 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 expire the password and -e to change the shell instead of the obvious -e and -s respectively. Viewed from here and now, such decision looks like it was asking for trouble. Commented Jan 24, 2020 at 18:05

You must log in to answer this question.

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