SSH Login Problem – User switching with su. Environment variables and SSH authorized_keys
Scenario
client – user mathias
client – user root
server – user root
In the server authorized_keys i entered the key of the client mathias. I can successfully connect to the server via ssh.
Then i made a „su“ from the user mathias and i got the root shell. Then i connected to the server via the user root and it was also successfully but i didn’t copied the key to the authorized_keys of the root user.
After a few debugs i figured out that just the command „su“ doesn’t change the whole environment.
With „su -“ the environment is changed completely and after that i got my permission denied.
Solution:
su -
Debug
mathias@workstation:~/.ssh$ su
Passwort:
root@workstation:/home/mathias/.ssh# ssh root@192.168.2.130
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-22-generic x86_64)
mathias@workstation:~/.ssh$ su –
Passwort:
root@workstation:~# ssh root@192.168.2.130
Permission denied (publickey).