1

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?

1 Answers1

1

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.

cas
  • 78,579
  • btw, yet another alternative is to configure 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 withssh root@localhost. But there's no advantage of doing this over just usingsudo -iexcept that it doesn't requiresudoto be configured to allow your user to run any command as root...although it does require initial root access (e.g. viasu` and the root password - which is yet another way of getting a root sh). – cas Apr 13 '16 at 06:39
  • Is there a possibility to have administrative privileges forever? –  Apr 13 '16 at 14:32
  • Yes, by logging in as root and not bothering to have or use a normal user account. But don't do that, it's a dangerously bad idea and you will one day regret it. Use root for admin tasks only, and your normal user account (or accounts) for everything else. – cas Apr 13 '16 at 22:18