Pergunta

I have a server, and three people access that server as user test with their SSH keys, their public keys is saved in authorized_keys file.

Is there a way to map a user to a ssh key. For example if user with public key A1 log in to the server, then i can match the A1 key to a person name in a config file or a small table(created by me) and get the name of the active users. How can i check what are the ssh keys used to log in to server, and are currently active, is there a way to do this ?

Foi útil?

Solução

Form the manpage we can read that you can set environment variables in the authorized_keys file for every key. For this to work you need to set

PermitUserEnvironment yes

in /etc/ssh/sshd_config and restart your ssh server.

Then add an environment="name=value" in front of the ssh public key in the authorized_keys file, like this for example:

environment="sshuser=user1" ssh-rsa AAAA...

If you then log in to the server you can access the env variable:

$ ssh server
$ echo $sshuser
user1

Hope it helps!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top