LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How do I add a user to be able to sudo? (https://www.linuxquestions.org/questions/slackware-14/how-do-i-add-a-user-to-be-able-to-sudo-883025/)

george-lappies 05-27-2011 08:02 AM

How do I add a user to be able to sudo?
 
How do I add a user to be able to sudo?

coolsreejith 05-27-2011 08:05 AM

iam not sure about Slackware but in rhel it is by the command visudo

TobiSGD 05-27-2011 08:06 AM

You have to add the user to the /etc/sudoers file, using visudo.
For more information have a look at
Code:

man visudo
man sudoers


AlucardZero 05-27-2011 08:07 AM

Have you read the manual or searched the web? It would be quicker than waiting for a reply, and you would learn something.

http://www.gratisoft.us/sudo/sudoers.man.html
http://www.syntaxtechnology.com/2009/06/sudo-tutorial/

Summary:
1. As root, run "visudo" to edit the sudoers file
2. Add a line for the user you want. Most people just do "username ALL=(ALL) ALL" but some would argue this is not what sudo is meant for.
3. Save and quit

Woodsman 05-27-2011 01:07 PM

As mentioned, the normal way is to use the /usr/sbin/visudo command.

Technically you do not have to use visudo, but the /etc/sudoers file normally has 440 permissions. To manually edit sudoers without visudo requires manually changing the permissions, edit the file, hope you do not make any silly editing mistakes, and then reset the permissions. Do know that sudo complains if the permissions of /etc/sudoers is not 440.

Thus the basic advice is just use visudo. As you can guess from the command name, the default editor that is used is vi. Elvis is the default vi in the stock Slackware. Fortunately, the stock Slackware build script uses the --with-env-editor build option. If you set the EDITOR or VISUAL environment variable to your preferred console text editor, then you will not be forced to use vi to edit the /etc/sudoers list. I use mcedit. :)

MTK358 05-27-2011 01:47 PM

Quote:

Originally Posted by Woodsman (Post 4368857)
If you set the EDITOR or VISUAL environment variable to your preferred console text editor, then you will not be forced to use vi to edit the /etc/sudoers list.

Like this:

Code:

EDITOR=your-favorite-editor visudo
visudo is not the only command that relies on the EDITOR variable. You can add this line to your ~/.bashrc if you want your editor setting to stay:

Code:

export EDITOR=your-favorite-editor
I'm not sure if you have to specify the full path or just the name. I'd put in the full path, just to be safe.

ruario 05-27-2011 03:03 PM

After you have added your user account you might want to update your user's $PATH to include /sbin and /usr/sbin so that you don't have to type the full path for admin commands when running them with sudo

samac 05-27-2011 04:40 PM

Or you could forget all about sudo and use su or su -, just add your user to the wheel group.

samac

w1k0 05-27-2011 08:43 PM

The more sophisticated /etc/sudoers file than:

Code:

username ALL=(ALL) ALL
would be:

Code:

Defaults    timestamp_timeout = 0

User_Alias  FULL = john
User_Alias  PART = mary

Cmnd_Alias  KILL = /bin/kill, /bin/killall
Cmnd_Alias  HALT = /sbin/reboot, /sbin/halt, \
                  /usr/local/bin/suspend
Cmnd_Alias  MOUNT = /bin/mount, /bin/umount

root ALL =  (ALL) ALL

FULL ALL =  NOPASSWD: KILL, HALT, MOUNT

PART ALL =  PASSWD:  KILL, HALT, \
            NOPASSWD: MOUNT

As you can see in this case user john has full access to all commands while user mary has restricted access to kill, killall, reboot, halt commands and suspend script (she have to confirm these commands using her password).

mRgOBLIN 05-28-2011 03:06 AM

As Samac suggested just use "su -" and worry about sudo later... (if you still feel you need it)

Sudo is primarily aimed at giving certain users fine grained permissions to do certain tasks as root (with or without giving away the root password).

Ubuntu and friends totally bastardised/mis-used it making it seem to be the be-all and end-all of user safety/security.

GazL 05-28-2011 04:53 AM

Quote:

Originally Posted by samac (Post 4369006)
Or you could forget all about sudo and use su or su -, just add your user to the wheel group.

No requirement to be a member of the wheel group unless you've locked it down in login.defs

ruario 05-28-2011 05:13 AM

Quote:

Originally Posted by mRgOBLIN (Post 4369277)
Ubuntu and friends totally bastardised/mis-used it making it seem to be the be-all and end-all of user safety/security.

Indeed, I have said this elsewhere but I think it is worth repeating here. For a home desktop/laptop set-up in particular, where typically only one person admins the machine there is no real advantage to sudo.

Consider if I wanted to run the fake command 'example' once as a root user. Here is what I would actually have to type (where $password is my actual password).

Using su:
su[Enter]$password[Enter]example[Enter][Ctrl]+d
(Note: That is '[Ctrl]' and 'd' together to exit the root session, you obviously aren't typing the '+' character)

Using sudo:
sudo[space]example[Enter]$password[Enter]

Ignoring the characters needed that are the same in both cases (i.e. 'example' followed by [Enter] and your password followed by [Enter]), you have to type 5 key presses to execute a single command as root via 'su' (s u [Enter] [Ctrl] d) and 5 key presses to execute a single command as root via 'sudo' (s u d o [space]). Or to put it another way, you save nothing using sudo.

If however you wanted to type two or more commands as root, you immediately start saving on the key presses by using 'su' instead of 'sudo'. Yes the second 'sudo' command does not require a password but as long as you have not closed your root session yet (i.e. no Ctrl+d) you don't have to type your password again with 'su' either and you save having to write 'sudo' for every single line.

There is also the point that outside of distros where 'sudo' is preconfigured (e.g. Ubuntu and derivatives) you save time configuring '/etc/sudoers' and setting up various admin variables for your regular user.

Indeed the other nice thing with using 'su' is that you can just open a root terminal for all your admin needs and you decide if and when you should close it, rather than relying on preconfigured time-out periods with 'sudo'.

george-lappies 05-28-2011 05:37 AM

Thanks all for the great responses. After some more reading I will be sticking with 'su -l' for now

psionl0 05-28-2011 06:10 AM

This is what I added to my sudoers file:
Code:

psionl0    ALL=(ALL) NOPASSWD:/sbin/shutdown
This allows me to shut down my pc via the fluxbox menu without giving me permission to use any other root commands.
For all other root functions, I use "su".

samac 05-28-2011 06:52 AM

Quote:

No requirement to be a member of the wheel group unless you've locked it down in login.defs
When did that change? It was set to yes in Slackware 10, so I've just kept adding myself to the wheel group.

samac


All times are GMT -5. The time now is 12:22 AM.