Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently got into trouble because of this.

$sudo vim /etc/motd 
[sudo] password for bruce: 
bruce is not in the sudoers file.  This incident will be reported.

Is there a way to check if I have sudo access or not?

share|improve this question
Ask your systems administrator? – mdpc Feb 18 '13 at 19:40
@mdpc: Is there another way besides that? – Bruce Feb 18 '13 at 19:45
You have not mentioned if you can attain root access or not. – mdpc Feb 18 '13 at 19:46
This has to be the first instance of seeing someone following up on "This incident will be reported". – slhck Feb 18 '13 at 19:55
up vote 45 down vote accepted

Run sudo -v. It is usually used to extend your sudo password timeout, but can be used for determining whether you have any sudo privileges.

$ sudo -v
Sorry, user [username] may not run sudo on [hostname].

Man page excerpt:

If given the -v (validate) option, sudo will update the user’s time stamp, prompting for the user’s password if necessary. This extends the sudo timeout for another 5 minutes (or whatever the timeout is set to in sudoers) but does not run a command.

If your user is only allowed to run specific commands, this command will work, indicating you are allowed to run something with different privileges. While the message looks different when trying to execute a command you're not allowed to in this case (and no mail is sent to root), it's still possible you'll get into trouble if the admins read /var/log/secure.

$ sudo ls
[sudo] password for [username]: 
Sorry, user [username] is not allowed to execute '/bin/ls' as root on [hostname].

To find out what you're allowed to run with different privileges, you can use sudo -l. Note that this command requires you to enter your password.

share|improve this answer
Thanks. sudo -v works for me. The man page says I can run sudo -l as well but that asks for a password. Why is that? – Bruce Feb 18 '13 at 20:00
@Bruce I'm guessing here, but otherwise someone (or a program you run) could find out what programs can be executed (possibly without entering password) by your current user and try to use that information maliciously. – Daniel Beck Feb 18 '13 at 20:05
What do you suppose it means when I get this back: patrick@<host>:~$ sudo -v sudo: unable to resolve host <host>? I entered my password and didn't get anything about unauthorized. I know I have sudo from successfully running other commands, but that unable to resolve host message has me concerned something else might be funky on the host. – Patrick M Apr 21 '14 at 3:04
@PatrickM It looks like a problem with the sudoers file. In there you can specify on which host a user is authorized to run a specific command (this is useful when using the same sudoers file on multiple machines). Possibly the hostname specified in that file could not be resolved. Try checking it with the host command for example. – Ale Dec 17 '14 at 23:10

This is very simple. Run sudo -l. This will list any sudo privileges you have.

share|improve this answer
Maybe downvoted because it repeats what Daniel Beck said nearly two years ago. – G-Man Dec 18 '14 at 4:09
Or explains what happen, it's a comment, at best – Ramhound Dec 18 '14 at 20:47
@Jonathan: if u would script in ubuntu rigt now, sudo -l asks for a password if u can sudo or not. sudo -v asks only if u can, and "$(whoami)" != "root" will never ask anything in any linux. – bksunday Aug 3 '15 at 3:37
@bksunday You are correct. I tested now on a clean Debian Jessy and confirmed your results. My previous (deleted now) comment was probably a result of testing on a machine on which I had some sudo privs. – Jonathan Ben-Avraham Aug 3 '15 at 4:30
@G-Man but this simple answer helped me more than probably more precise Daniel's answer, where this command is the the very end unfortunatelly... – Betlista Jan 4 at 14:48

Here is the script-friendly version:

timeout 2 sudo id && echo Access granted || echo Access denied

since it won't stuck on the password input if you do not have the sudo access.

share|improve this answer

Follow these steps to view the sudoers file. If you're in there, you have sudo. If not, you can add yourself.

  1. su
  2. visudo
  3. Bottom of the file, enter your_username_here ALL=(ALL) ALL
  4. Hit ESC and type :wq
  5. Type exit
  6. Re-run your command that needed sudo
  7. Enter your password (not the root's password)
share|improve this answer
The OP "got into trouble" for running sudo, so he probably isn't the system administrator, nor even one of the elite system administrators. He's probably just a user who thought he might have been granted some limited powers. What makes you suspect that he can go su? – Scott Aug 20 '14 at 20:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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