How to download a file from aws server using SSH?
Solution 1
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.
Solution 2
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 [email protected]:/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).
Related videos on Youtube
Lefty G Balogh
Updated on September 18, 2022Comments
-
Lefty G Balogh over 1 year
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?
-
Jakuje over 7 yearslog in to the server as that user? Copy the file as root to
ec2-user
accessible location and usescp
?
-
-
phk over 7 yearsPlease elaborate how the file will differ. I'm genuinely interested.
-
Tigger over 7 years@phk I added some details to the answer.
-
Lefty G Balogh over 7 yearsYour 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 over 7 yearsYour 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.