Skip to Content

Configure Automatic su or sudo

How to configure Automatic su or sudo /switch user CentOS/Freebsd/Ubuntu servers?


synopsis: This article provides step-by-step instructions for adding a server to Ezeelogin, detailing the necessary configurations for remote SSH login using either sudo or su commands to switch to the root user.


Check out the following video to ensure that you have configured the auto login correctly.

 

Add a server by providing Hostname, IP Address , Remote SSH login user and Password of the Remote SSH login user.

 

METHOD 1

switched to root using sudo

step1. Ensure that the remote ssh user has the bash shell enabled.

The finger command would let you know the currently assigned shell for the remote ssh user.

finger devops

Login: devops Name: devops

Directory: /home/devops Shell: /usr/local/bin/tsh

You may assigned bash shell to the user using the command

chsh -s /usr/local/bin/bash devops


step 2. You would now need to identify the 'First Prompt' . To find it, login as the ssh user and you will get the prompts

devops@ec2:~$%  

In this case the 'first prompt' would be '$% '. 

Important Note: There is the space character included above,  so totally  3 characters are required.

step 3. Now if you are switching to root user using sudo, then you would need to 'enable sudo' under Servers->Edit->Advanced section  and enter the 'root prompt' field.

[root@ec2~]# 

In this case the 'Root Prompt' would be ']# ' 

step 4. Once you fill in the 'first prompt' and 'root prompt' then you need to take a look at the 'Password Prompt' variable.

root@ec2:~$% sudo su -

[sudo] password for devops:

The 'Password Prompt' would be '[sudo] password for devops:' 

Once you have filled in all the three variables click on save button.

After saving  login to the Ezsh shell. Upon successful login to the Ezsh shell, you will initially be logged in as the Remote SSH login user to the remote server and then automatically switched to the root user.

Important Note: Enable sudo only if you want sudo command to switch privilege. If you are using 'su' command to escalate privileges, then leave the Privilege Escalation field as "None"

 

METHOD 2

switched to root using su

If you are using su instead of sudo to switch to root user then you need not enter the 'root prompt' and should disable sudo. Also you would need to enter the field 'Switch User' and 'Switch User Password' 'Switch User' would be 'root' and the 'Switch User Password' would be the root password.

Login to the Ezsh shell. Upon successful login to the Ezsh shell, you will initially be logged in as the Remote SSH login user to the remote server and then automatically switched to the root user using su.


Related Articles

Enabling Virtualshell did not allow automatic su or sudo

How to add a subssh user with non privileged remote ssh login user

Enable root privilege for the group in the sudoers file

How to add sub ssh users on remote servers and restrict commands via sudoers file

How to allow the user to switch when the command guard is enabled