ssh, scp, su -i -u someuser

Today I struggled with downloading a file through ssh.

I can ssh through server with account quynh.nguyen. However, in order to read the file, I must use another account

sudo -i -u someuser

Then when I issue a request to download a file from remote server to local machine. It’ll ask me for the password of someuser, which I do not have. I only have password of user quynh.nguyen.

scp ~/local_directory

The solution seems to be trivial, but I spent around 3 hours with the help of some friends to figure it out.

  1. ssh to server with quynh.nguyen account
  2. Use the shell of someuser
  3. scp to copy file from someuser to quynh.nguyen home folder. Then I’ll input the password for user quynh.nguyen
  4. scp to copy file from home folder of quynh.nguyen to local folder in my machine

Below is the code:

  1. ssh ....
  2. su -i -u someuser
  3. scp /home/someuser/some_file.txt
  4. scp* ~/local_directory