Is there a possibility to grant administrative privileges to the current logged in user forever?
So I don't have to type sudo
everytime I want to do something?
Is there a possibility to grant administrative privileges to the current logged in user forever?
So I don't have to type sudo
everytime I want to do something?
If /etc/sudoers
allows your user to run ANY command as root (and not just a limited pre-defined set of commands) then you can run sudo -i
to get a root login shell. You'll be able to run commands as root until you exit
that shell, without having to preface every command with sudo
.
e.g.
$ sudo -i
# id
uid=0(root) gid=0(root) groups=0(root)
# command-requiring-root
# another-command-requiring-root
# yet-another
# and-one-more
# exit
$ id
uid=1000(cas) gid=1000(cas) groups=1000(cas),[...]
BTW, if you have a default PS1 (or one containing \$
) then your prompt will change from $
to #
when you are root.
Alternatively, you can use sudo -s
to get a non-login root shell. The difference is that a login shell sets the environment (and sources /root/.bash_profile
etc) as if root had logged in. A non-login root shell just runs your shell as root, with the environment modified/restricted by sudo
as for any other command.
sshd
to allow root logins for authorised keys only (e.g. via PermitRootLogin=prohibit-password
in /etc/ssh/sshd_configand by adding your user's PUBLIC ssh key to
/root/.ssh/authorized_keys). Then you can login as root with
ssh root@localhost. But there's no advantage of doing this over just using
sudo -iexcept that it doesn't require
sudoto be configured to allow your user to run any command as root...although it does require initial root access (e.g. via
su` and the root password - which is yet another way of getting a root sh).
– cas
Apr 13 '16 at 06:39