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 quynh.nguyen@abc.com:home/someuser/some_file.txt ~/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 quyhn.nguyen@abc.com:/home/quynh.nguyen/some_file.txt
  4. scp quynh.nguyen@abc.com:/home/quynh.nguyen/* ~/local_directory 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s