Can I use
scp to copy a file from a remote server which my login user can't read, but where I have permission to sudo to root (without password even)? How?
ssh firstname.lastname@example.org sudo cat /path/to/restricted_file > /local/path
sudo requires typing in a password you will want to add
-t just after the
ssh in order to type in the
What this does is run
sudo cat file on the remote host, redirecting the output to a local file. On your local machine the file will be created by your shell with local user privileges.
You should be able to do this by logging on to the remote machine with
ssh and then launching the
scp command from the remote machine to your local one:
ssh user@remote sudo scp /path/to/file email@example.com:/local/path
I personally needed to gather a number of files I could only read with sudo and I wanted to do it in one go.
ssh user@remote 'cd /path/to; sudo tar zcvf - files*' > files.tar.gz
From there you just have to tar xf the file and get all of the files you want.