Sudo !! Tips and tricks

Sudo !! Tips and tricks

I recently discovered some cool sudo tricks. First of sudo is a way to get elevated privileges but not get full root access. As root you can do system administration tasks, that you are not allowed to as a normal user. The things you can “sudo” are defined in the so called sudoers file and can be edited by the following command:

visudo

It will look for a program to open the sudoers file with in the EDITOR variable.

Now say you have been granted sudo rights to manage a systemd service and you typed the following command:

systemctl restart httpd

This will no doubt give you a privilege error. Instead of using arrow up and altering the command to type sudo in front of it try this:

sudo !!

This will make you execute the previous command with sudo.

Bash completion with sudo

I had trouble with bash completion when using sudo, turns out to be an easy fix:

# Add complete -cf sudo to
sudo vim /etc/bash.bashrc
source /etc/bash.bashrc

Bash completion should now work for sudo.

Sudo will not use aliasses

When executing “sudo vi” it will not look to see if “vi” has an alias. The trick is to add an alias for sudo.

alias sudo='sudo '

The space will tell it to go and look for aliases of the command that you want to sudo.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.