Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch user with "sudo su - username" using SSH keys

I've been trying to use ssh keys in order to be able to switch from one user to another user on the same Linux machine/server by using sudo su - username.

What i want to do is: I have several accounts on one server. I want to lock those account with passwd -l username, and allow access only with SSH keys, by ssh-ing from one user to the other on the same machine, e.g., : [user1@server]$ ssh user2@server

I did this by copying the public key of user1 to the authorized_keys file of user2 and it works fine.

But the other thing that i would like also to do, is to be able to sudo su - user2 from user1, by using the ssh keys, so i can avoid the password prompting.

e.g., [user1@server]$ sudo su - user2

I have modified the sshd_config file, and uncomment the fields:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no

but still i am not able to do it.

I also tried what i found on the internet regarding agent forwarding, but nothing.

Can anyone help me on how to do this or point me to the right direction?

like image 237
Pier Avatar asked Jun 12 '13 09:06

Pier


1 Answers

sudo has nothing to do with SSH and sshd config.

What you really want is a PAM module that will use SSH public keys. I'm not sure what are your reasons as the whole idea seems a bit strange, but, well. pam_ssh is the module that does this.

like image 190
kirelagin Avatar answered Oct 15 '22 01:10

kirelagin