Saturday, April 2, 2016

How to Use SUDO in Debian

If you are a long time Ubuntu user who wants to try out Debian for fun, like myself, you may encounter
$ sudo apt-get install vim
-bash: sudo: command not found

This is because by default Debian doesn't come with sudo package. What you will need to do then is to use su command
$ su
Password: [root password]

You should now be able to login as root. Let's install sudo package first
# apt-get install sudo -y

Looks all good. Let's log out root and try sudo again
# exit
$ sudo apt-get install vim
[sudo] password for xxx:
xxx is not in the sudoers file.  This incident will be reported.

OK this is a bit scary. The incident has been logged to/var/spool/mail/xxx file.
Well, how do we then add a user to become a sudoer? First, login as root again and then you run the following
$ su
# adduser xxx sudo
where xxx is the username that you'd like to add to the sudo group.

When done, you will need to re-login with xxx in order for this to take effect. Let's just reboot the system.
# reboot

After the reboot, you should be able to now type in sudo command to do administrative tasks
$ sudo apt-get install vim

By the way, in case you are wondering how to disable local root login in Debian system, just like Ubuntu, this is what you'll need to run the following command as a sudo user
$ sudo passwd -dl root

To enable root account, you will need to
$ sudo passwd root

No comments:

Post a Comment