The right way to Change (su) to One other Person Account with out Password

0

Get real time updates directly on you device, subscribe now.

On this information, we are going to present the best way to change to a different or a selected consumer account with out requiring a password. For instance, we have now a consumer account referred to as postgres (the default PostgreSQL superuser system account), we would like each consumer (usually our PostgreSQL database and system directors) within the group referred to as postgres to change to the postgres account utilizing the su command with out getting into a password.

By default, solely the foundation consumer can change to a different consumer account with out getting into a password. Some other consumer will probably be prompted to enter the password of the consumer account they’re switching to (or if they’re utilizing the sudo command, they are going to be prompted to enter their password), in the event that they don’t present the right password, they get an “authentication failed” error as proven within the following screenshot.

User Authentication Failure ErrorPerson Authentication Failure Error

You need to use any of the 2 options supplied under to unravel the above subject.

1. Utilizing PAM Authentication Module

PAM (Pluggable authentication modules) are on the core of consumer authentication on trendy Linux working techniques. To permit customers in a selected group to change to a different consumer account with out a password, we will modify the default PAM settings for the su command within the /and so forth/pam.d/su file.

# vim /and so forth/pam.d/su
OR
$ sudo vim /and so forth/pam.d/su

Add the next configurations after “auth adequate pam_rootok.so” as proven within the following screenshot.

auth [success=ignore default=1] pam_succeed_if.so consumer = postgres
auth adequate pam_succeed_if.so use_uid consumer ingroup postgres

Within the above configuration, the primary line checks if the goal consumer is postgres, whether it is, the service checks the present consumer, in any other case, the default=1 line is skipped and the traditional authentication steps are executed.

auth [success=ignore default=1] pam_succeed_if.so consumer = postgres

The road that follows checks if the present consumer is within the group postgres, if sure, the authentication course of is taken into account profitable and returns adequate because of this. In any other case, the traditional authentication steps are executed.

auth adequate pam_succeed_if.so use_uid consumer ingroup postgres

Configure PAM to Allow Running Su Command without PasswordConfigure PAM to Enable Working Su Command with out Password

Save the file and shut it.

Subsequent, add the consumer (for instance aaronk) that you just need to su to the account postgres with out a password to the group postgres utilizing usermod command.

$sudo usermod -aG postgres aaronk

Now attempt to su to the postgres account because the consumer aaronk, you shouldn’t be prompted for a password as proven within the following screenshot:

$ su – postgres

Add User to GroupAdd Person to Group

2. Utilizing Sudoers File

You can too su to a different consumer with out requiring a password by making some modifications within the sudoers file. On this case, the consumer (for instance aaronk) who will change to a different consumer account (for instance postgres) must be within the sudoers file or within the sudo group to have the ability to invoke the sudo command.

$ sudo visudo

Then add the next configuration under the road “%sudo ALL=(ALL:ALL) ALL” as proven within the following screenshot.

aaronk ALL=NOPASSWD: /bin/su – postgres

Add User to Sudoers FileAdd Person to Sudoers File

Save and shut the file.

Now attempt to su to the account postgres because the consumer aaronk, the shell mustn’t immediate you to enter a password:

$ sudo su – postgres

Switch to Other User Without PasswordChange to Different Person With out Password

That’s all for now! For extra data, see the PAM guide entry web page (man pam.conf) and that of sudo command as nicely (man sudo).

$ man pam.conf
$ man sudo

If You Respect What We Do Right here On TecMint, You Ought to Think about:

TecMint is the quickest rising and most trusted group website for any form of Linux Articles, Guides and Books on the internet. Tens of millions of individuals go to TecMint! to look or browse the 1000’s of revealed articles obtainable FREELY to all.

Should you like what you’re studying, please contemplate shopping for us a espresso ( or 2 ) as a token of appreciation.

Support Us

We’re grateful on your by no means ending help.

Leave A Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More