Switch user with "sudo su - username" using SSH keys
To get sudo to work passwordless to another user these are the changes required (perform them with super user access):
edit /etc/sudoers
visudo
Config changes
# Allow user to sudo su as anyone without passworduser ALL=(ALL) NOPASSWD: ALL%group ALL=(ALL) NOPASSWD: ALL# Allow user to become another useruser ALL=(user2) NOPASSWD: ALL%group ALL=(user2) NOPASSWD: ALL
now with the latter sudo su - user2 should work
The only stumbling block was the user to be added to sudo group
usermod -a -G sudo user
The examples above in the config shows the user first then by group - you only need 1 of the two -
Edited:
visudo%group2 ALL=(ALL:ALL) PASSWD: ALL%group1 ALL=(ALL:ALL) NOPASSWD: ALL
add run group
groupadd group1groupadd group2
so for users that require a password
usermod -a -G group2 user1usermod -a -G group2 user2etc..
for users that require no password:
usermod -a -G group nuser1usermod -a -G group nuser2etc