Search code examples
sshcopy-pastesudo

How to copy file from server to local using ssh and sudo su?


Somewhat related to: Copying files from server to local computer using SSH

When debugging on DEV server I can see logs with

# Bash for Windows
ssh username@ip

# On server as username
sudo su

# On server as su
cat path/to/log.file

The problem is that while every line of the file is indeed printed out, the CLI seems to have a height limit, and I can only see the last "so many" lines after the printing is done.

If there is a better solution, please bring it forward, otherwise, how do I copy the "log.file" to my computer.

Note: I don't have a password for my username, because the user is created with echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/$USER.


Solution

  • After sudo su copy the file to the /tmp folder on the server with

    cp path/to/log.file /tmp/log.file
    

    After that the standard command should work

    scp username@ip:/tmp/log.file log.file
    

    log.file is now in the current directory (echo $PWD).