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

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.

  • 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_config` and 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 -i except that it doesn't require sudo to 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 6:39
  • Is there a possibility to have administrative privileges forever? – Raildex 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.