Is it possible to change passwords temporarily

passwordshadowusers

I have a Linux system with several users. I don't know their passwords, nor do I want to know them.

I have to do a batch copy of some of their directories over SSH, with their account and password.

My idea was to make a backup of /etc/shadow, then alter it with new passwords for each user (one that I know, like "tmppass"), do my backups, then replace the /etc/shadow file with the old one.

Will that work? If so, how do I generate the password/s? (The passwords are like $1$xxxxxx/xxxxx).

Best Answer

Just backup the /etc/shadow file, and change the users passwords with passwd:

  • Backup the shadow file:

    sudo cp /etc/shadow /etc/shadow.bak
    
  • Change the password of the user you want to access (e.g. testuser):

    sudo passwd testuser
    
  • When done, restore the /etc/shadow file from the backup:

    sudo mv /etc/shadow.bak /etc/shadow
    

    Note that all passwords should be reset to the passwords they were when they were backed up.

Works on Fedora 19

N.B. Not what you asked, but it would be much easier to access those users with:

sudo -u testuser bash

This only require authentication with sudo, not as that user.

Related Question