Add a line for your username in the /etc/sudoers file, allowing you to sudo in Fedora

echo 'loginname ALL=(ALL) ALL' >> /etc/sudoers
I am new to linux, and I was trying to figure out why I could not sudo with my username in Fedora 10. This command, when run as root, will add a line to the sudoers file allowing the loginname supplied to sudo. The above line will require a password when you sudo, if you wish to sudo without password, use: echo 'loginname ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers instead. you have to run this command as su, and this is just an easier way of using visudo, just adds it right from the terminal.

By: refrax
2009-03-19 13:23:43

What Others Think

uh-oh! Better to use: visudo
mpb · 624 weeks and 2 days ago
I'm curious why it's better to use visudo? Like I said, new to linux, wanting to learn what is good.
refrax · 624 weeks and 2 days ago
Visudo checks for correct syntax, so you can be sure your sudoers file will work: [email protected]:14:39:0:/home/alanceil> visudo [editing...] >>> /etc/sudoers: syntax error near line 2 What now? From the manpage: visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors. If the sudoers file is currently being edited you will receive a message to try again later.
Alanceil · 624 weeks and 2 days ago
You should use visudo, or atleast substitute "$(echo whoami)" for 'loginname' ;-)
ozymandias · 624 weeks and 2 days ago
I'm sorry -- $(who am i | awk '{print $1}') would work better...
ozymandias · 624 weeks and 2 days ago
Use 'visudo' and nothing but 'visudo' (not 'awk', not 'echo', etc). If you don't have visudo, install it; if you still can't access it, then (and only then) you might resort to hacks--or rebuild your computer from the ground up!
alexandersafir · 624 weeks and 2 days ago
ok, well, no don't do that. sudo is an administrative tool, but that's what ubuntu has taught.. be root and do it all. There is a reason why windows fails giving the user administrative rights, and why root is a different user in Linux, and other users have less rights (the monolithic hiracy) visudo is good, but knowing your system is better. I voted down not because the method was wrong, but the idea was wrong.
JesusSuperstar · 624 weeks and 2 days ago
root is a design error
maht · 624 weeks and 2 days ago
@koukos Sudo is not a wrong idea. Sudo has been around long before Ubuntu. Mac OS X, for example, has been using sudo since day one, further by disabling root entirely (as does Ubuntu). Most major distributions and Unix derivatives ship sudo. Just because Ubuntu has made sudo popular doesn't make it a problem. Sudo has many advantages over just plain 'su - root': 1) It logs the actions of who is performing the command. 2) You can enforce granular control over who has access to what command and what hosts. 3) It creates a mindset of using least privilege, and preventing root logins. @maht I'll argue that with you. While the paradigm of an all-powerful user 'root', then everyone else is unfortunate, it's been addressed through the wheel group, sudo, and RBAC. Unix today is 100x better than it was 20 years ago. The root account now means more than it did. For @refrax who submitted the command, as people have already mentioned, 'visudo' is the tool you want to use, so you can check syntax errors. If a tool exists for editing a configuration file, then the tool should be used. 'visudo' is it.
atoponce · 624 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: