Environment: Remote: AWS - RHEL 7.2 Local: Ubuntu 16.04

I SSH into the AWS box directly using a .pem file for authentication, something along the lines of:

ssh -i /home/<user>/<path>/<serverkey>.pem ec2-user@ec2-<awsserver>.us-west-2.compute.amazonaws.com

What I want to do is simply download a file not owned by the root user, but by another user so the usual scp magic does not readily work.

Any suggestions?

  • 1
    log in to the server as that user? Copy the file as root to ec2-user accessible location and use scp? – Jakuje Oct 29 '16 at 20:57

Personally, I would look in to why sftp or scp is not working.

Technically you can do:

ssh -t user@host 'cat /path/to/file' > out.file

This may NOT produce an identical file, but might be good enough for what you want.

For example, my test case transfer produced a file with CRLF (dos) line terminators and the original had LF (unix) - I'm not sure why to be honest. The rest of the file was identical. No binary file was tested either.

The test was performed from Linux to FreeBSD.

  • Please elaborate how the file will differ. I'm genuinely interested. – phk Oct 30 '16 at 8:32
  • @phk I added some details to the answer. – Tigger Oct 30 '16 at 8:45
  • 1
    Your solution worked out as follows: ssh -i /home/<path>/<morepath>/key.pem -t ec2-user@ec2-<server>.us-west-2.compute.amazonaws.com 'cat /home/ec2-user/file.xml' > /home/<user>/Desktop/out.file Worked like a charm. Definitely worth an upvote. – Lefty G Balogh Nov 2 '16 at 20:12
 ssh — OpenSSH SSH client (remote login program)
 scp — secure copy (remote file copy program)
 sftp — secure file transfer program

use scp, or sftp. example usage;

scp ec2-user@ec2-blabla.com:/home/ec2-user/.bashrc download-bashrc.txt

all three work with the ssh daemon.

ps, to attain the file of another user make sure your user has read access to the file (either chmod/chown, or copy the file to your user's home).

  • Your solution also worked out real smooth. I shortcut the user rights and copied the file so ec2 could access it and then: scp -i /home/<path>/<morepath>/key.pem ec2-user@ec2-<server>.us-west-2.compute.amazonaws.com:/home/ec2-user/file.xml /home/<user>/Desktop Also worth an upvote. Thank you. – Lefty G Balogh Nov 2 '16 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.