sudo issue
Karl Auer
kauer at biplane.com.au
Mon Aug 1 11:11:14 UTC 2016
On Mon, 2016-08-01 at 12:25 +0200, Ralf Mardorf wrote:
> is there a way to set up sudo, that it is able to copy everything,
> when running a line such as
>
> sudo cp -rp /path/.foo /to/another/path/
With fully-qualified paths, the above will work fine. It's wildcards
that are causing problems for you.
The wildcard expansion happens on your command line, and the result is
passed to sudo. The permissions in force when the wildcard expansion
happens are yours, not root's. You as a non-privileged user can't "see"
everything in the path, so the expansion comes up empty.
Because ls does not try and fail to read any directories - it tries and
succeeds, but finds no such files, because it wan't passed them. That's
why the error message is "no such file" instead of "permission
denied".
If you executed the exact same command without sudo, you would see
"permission denied", which would be a big clue :-)
Here is the same thing simplified:
kauer at kt:~$ sudo touch /root/blah.txt
kauer at kt:~$ sudo ls /root
blah.txt
kauer at kt:~$ ls /root/*.txt
ls: cannot access '/root/*.txt': Permission denied
kauer at kt:~$ sudo ls /root/*
ls: cannot access '/root/*': No such file or directory
You can work around this by passing the command to a new shell,
protected by quotes:
kauer at kt:~$ sudo sh -c "ls /root/*.txt"
/root/blah.txt
Regards, K.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
http://twitter.com/kauer389
GPG fingerprint: E00D 64ED 9C6A 8605 21E0 0ED0 EE64 2BEE CBCB C38B
Old fingerprint: 3C41 82BE A9E7 99A1 B931 5AE7 7638 0147 2C3C 2AC4
More information about the ubuntu-users
mailing list