Monday, April 22, 2013

Log-in as root on Linux Terminal

I am going to show you three most used methods to log-in as root.

First way :
If you have sudo privileges as a user, you can use following command to log-in as root on terminal.
$ sudo -i
It asks for your (user's) password. After enter your password, you can log-in as root on terminal.

Second way :
$ su - or $ su - root
It asks for root's password. If you know root's password, you can log-in as root.

Third way:
You can log-in as root using secure shell (ssh)
$ ssh ip-of-the-server

If client and server are two different systems, the first two methods do not work to log-in as root on server. Only third method will work.

If client and server are in same system (root and users are in same system) , the first two methods do not require internet to log-in as root on terminal.

Third method requires internet to log-in as root on terminal.

Disable sudo privileges for user

If you want, user should not execute command with sudo.
To remove sudo permissions for user, follow the process.

1. Change the group of user. To see how to change the group of a user click here.

2. Do not define the group in file /etc/sudoers
     A group-name is started with symbol % in  /etc/sudoers
     Comment the line in /etc/sudoers
    #%group-name ALL=(ALL) ALL
Above line without comment gives sudo permission to all users of the group.
If you comment this line, no user of the group can use sudo while executing any command.

3. Now whenever user tries to run command with sudo, it says
 Error - username is not in the sudoers file. This incident will be reported.

Add username & group in sudoers file

Error - username is not in the sudoers file. This incident will be reported.


Open the file /etc/sudoers, Add following line in it
username ALL=(ALL) ALL
If your username is john, the line should be
john ALL=(ALL) ALL

If you want to add whole group as sudoers.
%group-name ALL=(ALL) ALL
where % indicates the name is a group.

If your group-name is wheel, the line should be
%wheel ALL=(ALL) ALL