![]() If you do not have sudo access, there are some other alternative ways, like ssh The sudo command is rather simple to use as long as it is installed and you have the required permission to use it. In general, you can rely on sudo to start a new shell as the user you like.The -u option allows you to specify your desired username: Read: How to use sudo without having to enter a password in Ubuntu You do not need to specify a username, If you want to login as root : Read: How to create a Sudo user on Ubuntu 167 Much simpler: use sudo to run a shell and use a heredoc to feed it commands. This shows the second user as the current user. $ man pam.To switch users in one terminal session, you could use the su command : That’s all for now! For more information, see the PAM manual entry page ( man pam.conf) and that of sudo command as well ( man sudo). Now try to su to the account postgres as the user aaronk, the shell should not prompt you to enter a password: $ sudo su - postgres Then add the following configuration below the line “%sudo ALL=(ALL:ALL) ALL” as shown in the following screenshot. In this case, the user (for example aaronk) who will switch to another user account (for example postgres) should be in the sudoers file or in the sudo group to be able to invoke the sudo command. You can also su to another user without requiring a password by making some changes in the sudoers file. Now try to su to the postgres account as the user aaronk, you should not be prompted for a password as shown in the following screenshot: $ su - postgres Next, add the user (for example aaronk) that you want to su to the account postgres without a password to the group postgres using usermod command. Create a new user account using the adduser command. Log in to your system as the root user: ssh rootserveripaddress. If you want to configure sudo for an existing user, skip to step 3. auth sufficient pam_succeed_if.so use_uid user ingroup postgresĬonfigure PAM to Allow Running Su Command without Password Follow the steps below to create a new user account and give it sudo access. Otherwise, the normal authentication steps are executed. To disable Unattended Upgrades on Ubuntu, run the following command: sudo nano /etc/apt//20auto-upgrades This will open the configuration file in the Nano editor. Running Script as Another User While logged in as user dave, we can run the annie-script.sh as user annie: su -c /home/annie/annie-script.sh annie Password: Running annie-script.sh as user annie By default, the su command takes an input a target username to switch into. The line that follows checks if the current user is in the group postgres, if yes, the authentication process is considered successful and returns sufficient as a result. In the above configuration, the first line checks if the target user is postgres, if it is, the service checks the current user, otherwise, the default=1 line is skipped and the normal authentication steps are executed. auth pam_succeed_if.so user = postgresĪuth sufficient pam_succeed_if.so use_uid user ingroup postgres # vim /etc/pam.d/suĪdd the following configurations after “auth sufficient pam_rootok.so” as shown in the following screenshot. ![]() To allow users in a specific group to switch to another user account without a password, we can modify the default PAM settings for the su command in the /etc/pam.d/su file. PAM ( Pluggable authentication modules) are at the core of user authentication on modern Linux operating systems. You can use any of the two solutions provided below to solve the above issue. Any other user will be prompted to enter the password of the user account they are switching to (or if they are using the sudo command, they will be prompted to enter their password), if they don’t provide the correct password, they get an “ authentication failed” error as shown in the following screenshot. For example, we have a user account called postgres (the default PostgreSQL superuser system account), we want every user (typically our PostgreSQL database and system administrators) in the group called postgres to switch to the postgres account using the su command without entering a password.īy default, only the root user can switch to another user account without entering a password. In this guide, we will show how to switch to another or a specific user account without requiring a password.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |