Does sudo really make you root for a while?
The man page for sudo
explains:
There is no easy way to prevent a user from gaining a root shell if that user is allowed to run arbitrary commands via sudo.
Thus, if you run sudo something
and type in your password; then, if you don't lock your terminal another user will be able to run sudo su -
within 5 minutes which will give him access to the root shell, if your sudo allows you to run arbitrary commands. For more on the timeout, I'm going to quote this relevant section from the above man page:
The sudoers policy caches credentials for 5 minutes, unless overridden in sudoers
. By running sudo
with the -v
option, a user can update the cached credentials without running a command.
Why do I get permission denied?
sudo
can not tamper with how bash works, which is why it can't deal well with features like file redirection and other features that work outside of the command. To avoid this you will have to ask a root shell to execute the full command, such that it does forward the redirection character to a rooted environment instead of parsing it.
As shown by the other user, this is as simple as running
sudo bash -c 'date > file'
or rewriting it such that you do not need the redirection parameter to be run as root, like so:
date | sudo tee file
sudo
-ers file (although one would thinksudo
would give the error). More likely, 2)sudo
is configured to run commands not asroot
, but another user.sudo date > file
Doesn't open the file as root. It opens the file and redirects the output ofsudo date
to that file.sudo (date > file)
you suggested results insyntax error near unexpected token 'date'
.