How can I scp a file that my user can't read but I can sudo?

Try this:

ssh [email protected] sudo cat /path/to/restricted_file > /local/path

If your sudo requires typing in a password you will want to add -t just after the ssh in order to type in the sudo password.

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 protected]:/local/path

Tags:

Ssh

Scp

Sudo