How do I add a user to be able to sudo?
How do I add a user to be able to sudo?
|
iam not sure about Slackware but in rhel it is by the command visudo
|
You have to add the user to the /etc/sudoers file, using visudo.
For more information have a look at Code:
man visudo |
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 |
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. :) |
Quote:
Code:
EDITOR=your-favorite-editor visudo Code:
export EDITOR=your-favorite-editor |
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
|
Or you could forget all about sudo and use su or su -, just add your user to the wheel group.
samac |
The more sophisticated /etc/sudoers file than:
Code:
username ALL=(ALL) ALL Code:
Defaults timestamp_timeout = 0 |
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. |
Quote:
|
Quote:
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'. |
Thanks all for the great responses. After some more reading I will be sticking with 'su -l' for now
|
This is what I added to my sudoers file:
Code:
psionl0 ALL=(ALL) NOPASSWD:/sbin/shutdown For all other root functions, I use "su". |
Quote:
samac |
All times are GMT -5. The time now is 12:22 AM. |