Have a situation that SCP and SFTP wouldn't work for. I've RTFM for SSH, but can't find what I'm looking for.

The scenario is that in order to transfer files to the server, I first SCP them into a user directory, then log in with SSH using a limited user account, SU to root, and then move the files where they need to be.

Because the server does not allow root login, is there a way to login with SSH, SU to root, and transfer files from the local machine?

Really I'm just looking for a more efficient practice then the going back-and-forth like I've been doing.

As a addition, I'd appreciate any links in the comments to GUI clients that would allow this on a Mac so I could drag & drop files from the local machine into the appropriate remote directory. An SFTP GUI client seems the logical choice, but the required elevated user permissions prevents it from doing what I need.

  • Any reason not to have a cron job (run as root) look in the user directory and move the files once they are there? Then you just have to copy the files. Then you can use sshfs to mount the remote user directory and drag and drop your stuff in there.
    – Anthon
    Feb 25, 2015 at 17:15
  • Interesting solution, though the destinations change for where the file would need to be, and this the work isn't regular enough.
    – Twitch
    Feb 25, 2015 at 17:23

1 Answer 1


On your local system, create a skeleton of what you want. For example, if you want to copy file foo to remote location /etc/foo, then you need to create an etc directory and then put foo into it. Then tar the skeleton. Now you can do this via cron as suggested by @Anthon in the comments to the question above.

Step by step:

On the remote host, create script like this:

if [ ! -s "$DROP" ]; then exit 0; fi
cd /
tar -pzxf "$DROP" && rm "$DROP"

On the remote host, add that script to a cron job that runs as root.

On your local host, create the skeleton and populate the files you want copied:

mkdir -p etc
mkdir -p var/www
cp -a foo etc/
cp -a bar var/www/
tar -pzcf drop.tgz etc var
scp drop.tgz REMOTEHOST:
rm -rf drop.tgz etc var

The drop.tgz will be extracted when the root's cron next runs. Note, this will overwrite all kinds of things that you might not like.

A safer option, assuming there are only a few files you need to modify, would be to make your user account have write access to them (chown or both chgrp and chmod g+w), then you can scp them directly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.