Linux – add a password to a user that already has ssh authentication

linuxpassword

I have a user account on my server to which i access through ssh key authentication.
I want to give a temporary access to that account to a third person.
I was planning to create a password as an alternative authentication method (hence the server will be accessible either by password or by ssh key), give it to that third person for her to perform a job, and then delete the password once the job is done.

How can i create (and then delete) such a password?

Best Answer

The answer to the password question is:

  • Edit the /etc/ssh/sshd_config file to ensure that passwords are enabled.

PasswordAuthentication yes 
PermitEmptyPasswords no

Then restart the ssh service (HT - @tonioc). This will work for sysvinit systems:

/etc/init.d/ssh restart

And this should work for systemd systems:

systemctl restart ssh

And then either:

  • Login with your key and change the passwd of the account if the password is locked.

Or (better):

  • Add a new user account for the new user and add that user to whatever minimum groups are required to accomplish the new user's task.

Or (even better):

  • Add a new user and have them give you a public key
  • Add their key to their ~/.ssh/authorized_keys file if they don't know how to copy it themselves.

However, for the least number of changes but rather poor security, you can simply add another key to:

~/.ssh/authorized_keys

on the server.

You can have as many keys as you want in the authorized_keys file. It's one key per line with options prepended.

There are many options that can be added to the authorized_keys file.

See here

And/or:

man authorized_keys

Of course, as others have pointed out, it's not a good idea to have more than one user per account unless it's run by a team. Temporary privileged access or accounts are probably not a good idea.

Related Question