19

I've searched for this, and the answer is probably in a million places on the 'net, but I can't find it...

How do you give your account root privileges in Linux so that you don't need to sudo every single command that requires privileges? It's even more annoying than Windows's User Accounts Control.

(Please... I don't need a lecture on how I would be living a dangerous life. Thank you.)

14

Does this work for you?

sudo EDITOR=gedit visudo

Change this line:

%admin ALL=(ALL) ALL

to this line:

%admin ALL=(ALL) NOPASSWD: ALL

No lectures. :)

| improve this answer | |
  • 3
    +1, but the trouble is, it still requires me to type sudo. – user541686 Jan 11 '11 at 19:19
  • @Lambert Ok, well, I don't want to do this to test it out, but I think you can just give root a password 'sudo passwd root '. Logout as your user; login as root. Now does GDM let root login? – user8290 Jan 11 '11 at 19:25
  • 2
    Well, I've already done that to set the root password and log in as root, and of course I don't need to sudo anymore. The trouble is finding out how to do the same thing for a different account. – user541686 Jan 11 '11 at 19:33
8

You don't. Two things you can do are:

1) Run sudo -s to stay root when you plan on entering multiple commands and don't want to keep prefixing them with sudo.

2) You can configure your sudoers file to allow you to run sudo without having to enter your password.

| improve this answer | |
  • 2
    Well, what I don't understand is, if I can just log in as "root" so easily and never have to even think about the word "sudo", then why can't I do the same thing in a different account? – user541686 Jan 11 '11 at 2:43
  • @Lambert: Because those other accounts are not UID 0. – JanC Jan 11 '11 at 3:47
  • 1
    Huh... so even adding myself to the group sudo or even something like that isn't enough? :( – user541686 Jan 11 '11 at 5:34
2

I don't see how hard it is to run sudo -i once in a terminal, and then just use this one terminal (or you could open more than one, but then you would have to type your password again) to do all your sudo stuff.

(And no, I can't really see the big problem in typing your password once in a while. It's really not that time consuming, and unless you close your terminal after each command, sudo will not ask for your pass for a while after you have authenticated).

| improve this answer | |
  • 3
    It's not that it's time-consuming, it's just that it's very irritating. If I say I want to change my login screen's wallpaper, I don't need an "Are you out of you mind?! I can't trust you." message asking me if I'm in fact sane for even thinking about performing such a High Privilege action, telling me that, if I put in my password wrong, this event will Be Reported. It's like my own computer doesn't trust me, and when you're working for a while, it gets God-darn annoying that other people's silly actions with the computer makes your own computer question you. – user541686 Jan 11 '11 at 10:23
  • Not meaning to take out my anger at this on you, but sometimes, "safety" features in software that are designed to protect inexperienced users just drive me nuts. If I want to make my computer explode, there's no need for anything more than an "Are you sure?!" message with a "Don't ask this again." box... any more, and it just defeats the purpose of having a confirmation at all. If I have to enter a confirmation for everything, there might as well not be one -- it's not going to change my determination, but at least I'll get the same things done five times as fast with none of the irritation. – user541686 Jan 11 '11 at 10:32
  • Ubuntu's security design is for a home environment with multiple users. System-wide changes should only be done by a trusted individual, not just someone who happens to have a user account or happens to be borrowing your account. – Jeremy Bicha Jul 31 '11 at 11:31
  • @JeremyBicha They did not add anything on top of the original unix security/authorization design which Imo was made for multiuser timesharing on mainframes... Wherther this ias appropriate for the home is another question but we are stuck with it. – masterxilo Dec 24 '18 at 3:32
1

You could install/activate the 'su' command and configure the shell to run it on startup.

| improve this answer | |
  • Is there any more "direct" way? Such as using sudoers or by adding myself to some special group? – user541686 Jan 11 '11 at 1:19
  • sudo -s does the same thing. – psusi Jan 11 '11 at 2:37
  • @psusi: But isn't the point of the question precisely to not have to do that every single time I start the computer? – user541686 Jan 11 '11 at 2:41
  • Is there any way to make it not ask for the password every single time? – user541686 Jan 11 '11 at 10:39
0

The correct answer to my question:

You can change your user ID (UID) and group ID (GID) to zero in /etc/passwd, to gain root privileges.

However:

If you do, you will not be able to log back in!

You can, nevertheless, create a new user, and change his group/user ID to 0. Essentially, that user will be another root, but with a different profile folder, etc.

Then you can use that profile as if you were root Himself! :D

Another "solution":

(if you like blank passwords)

  1. Run the commands below, and compare the outputs

    sudo cat /etc/shadow
    sudo sed "s/\(^$(whoami):\)[^:]*/\1/" /etc/shadow
    

    You should see that the latter has removed the gibberish in front of your username (which is read using $(whoami)). (If you don't, don't continue!)

  2. When you're ready, run the command to overwrite /etc/shadow (at your own risk!)

    sudo sed -i.bak "s/\(^$(whoami):\)[^:]*/\1/" /etc/shadow
    
  3. Your account now has a blank password, and you should no longer be prompted for sudo permissions. (At least, that's what happened to me.)

Note:

You may also need to enable passwordless login; I'm not sure if that's necessary, though.

| improve this answer | |
  • I have read somewhere that using "sudo bash" do the job. Have you tried this ? – Curious Apprentice May 4 '12 at 3:09
  • @CuriousApprentice: The whole point was to avoid sudo. – user541686 May 4 '12 at 4:04
0

I advice STRONGLY not to give yourself GID 0. SUDO is not there to make things compicated. Only reason to make another root account (wether home directory is /root/ or custom directory i.e. /home/root2/) is that there is two administratos in system who does not wish to share one root password.

Otherwise, use sudo. And assuming you are not seasoned Unix-user, there is also risk you forget what tools are root-only and what is for common users.

BUT, if you feel that you have secure normal user (i personally use STRONG password with this method), i let my user (i.e. tatu.staff / uid=1xxx, gid 50) run SUDO without password. Therefore I never mix up what is only for root and what's for user.

Use instructions above to create sudoers file (and corresponding groups) to make specific user to run SUDO without password or see example file i'll paste here:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Defaults        !authenticate

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
YOURUSER    ALL=(ALL) NOPASSWD:ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
%wheel  ALL=(ALL) NOPASSWD:ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

YOURUSER being your username, that line allowing specific user to run SUDO without password.

all users in group SUDO need to give password.

all users in group wheel can run sudo without password -- useful if you want to give passwordless SUDO ACCESS to multiple users, which is by the way, simply put A VERY BAD IDEA.

ALSO: - Remember the % charachter before GROUP names. - One can edit /etc/group directly, but it is NOT adviced. Use ADDGROUP to edit, see more info by typing: man addgroup

I must stress again that ALWAYS edit sudoers file by using VISUDO command, NEVER directly with editor. That ensures that you always get valid sudoers file - typing errors or bad statements etc. are very bad thing in such important file, and visudo saves you all that trouble you might not be able recover by yourself, and i bet first answer to question after this is "always use visdo. didn't they tell you that? oh they did? What is wrong with you?" or something alike ;)

--

Greetings from Finland - it's nice, quite nice winter here, only -10 Celsius, not those awful lower than -25 C temperatures.

\\ tatu-o

| improve this answer | |
  • Also, if you dont want to write long commands or tend to forget --flags, aliseses are there for you! Check ~/.bashrc that alias file is set, and then add you aliases to ~/.bash_aliases – tatu stty Nov 24 '16 at 21:25

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.