How do I transfer files over ssh after sudo?
Solution 1
I assume that you do not have the password to the other user account, nor to the root account, and/or the remote host does not allow direct root login via SSH.
If it is not too much data, I would just SSH in beforehand, become root, create a tarball of the data, grant access to the tarball for your regular user, then download the tarball as your regular user.
Solution 2
You can use something like tar to and pipes to do this (as long as you have tar available on both hosts). For example, to copy root's homedir over to another host:
sudo tar c -C / root | ssh remote_host tar xv -C some/location/to/unpack/into
(assuming gnu tar for -C support, it can be done without it using '()' but it's trickier) and of course, you can do the sudo on the remote end:
tar c -C my_trojan_files . | ssh remote_host sudo tar xv -C /usr/bin
The trick here is that, in both cases, tar is emitting the archive to STDOUT, which is being piped into the command running on the remote host via ssh. You can do this with cpio and dump/restore as well.
Solution 3
You can, using scp. It's done like this:
scp <file to transfer> user@server:/place/to/put/file
scp is provided by ssh in the package openssh-client
For more info, type 'man scp'.
Solution 4
You can install winscp on your Windows box to pull the files from your Ubuntu machine over ssh. http://winscp.net
Their site has instructions on su-ing to another user after logon: http://winscp.net/eng/docs/faq_su
Related videos on Youtube
Sebastian Thiele
Updated on September 17, 2022Comments
-
Sebastian Thiele over 1 year
I have access to a box over SSH and there are some files I'd like to transfer to another machine, but those are only accessible under another account
If I
ssh
with 1, thensudo
2 I can browse them.What I want actually is a mirror to copy them over to my Windows-based PC
How can I achieve that if only SSH is available?
-
maco over 13 yearsDo you mean
sudo su 2
?
-
-
waspinator over 12 yearsis there an easier way of doing this yet? I want to copy files I only have sudo permissions to but taring them every time isn't fun. Is there really no way to scp as sudo on remote host?