How to copy a directory which root can't access to a directory that only root can access?
You can use tar
as a buffer process
cd .rubies
tar cf - ruby-2.1.3 | ( cd /opt && sudo tar xvfp - )
The first tar
runs as you and so can read your home directory; the second tar
runs under sudo
and so can write to /opt
.
You could use rsync
or scp
to copy from user@localhost
to the local directory.
Example for rsync
:
# rsync "$real_user@localhost:$PWD/.rubies/ruby-2.1.3" /opt
You could alternatively
$ rsync .rubies/ruby-2.1.3 "root@localhost:/opt"
if you let root access localhost directly (not recommended; we normally prefer root access to be via sudo
).