This happens a lot to me, I usually forget to start a command with sudo, and therefore I had to run it again. If you run into this problem run:

sudo !!

And the last command run, will be run again but this time with the command sudo in front of it.

i.e.

[user@myhost ~]$ /etc/rc.d/sshd restart
:: Stopping Secure Shell Daemon                                          [FAIL] 
:: Starting Secure Shell Daemon                                          [FAIL] 
[user@myhost ~]$ sudo !!
sudo /etc/rc.d/sshd restart
Password: 
:: Stopping Secure Shell Daemon                                          [DONE] 
:: Starting Secure Shell Daemon                                          [DONE]

In the example above, I entered the command without sudo command and ssh daemon failed to restart. After that, I just entered the command sudo !! and it asked for my password, and this time worked.

Sudo before vim/vi

If you forget to use sudo, when editing files not belonging to you, you will not be able to save it after editing. This is very frustrating specially if you had edit a lot of it, but there is a way around.

:w !sudo tee %

Use the command above while editing in vim, then just quit, the file will be saved with the changes.

You may also be interested in: sudoers file And Prevent Linux to “remember” your sudo password