client – user mathias
client – user root
server – user root
In the server authorized_keys i entered the key of 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.
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 –
root@workstation:/home/mathias/.ssh# ssh email@example.com
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-22-generic x86_64)
mathias@workstation:~/.ssh$ su –
root@workstation:~# ssh firstname.lastname@example.org
Permission denied (publickey).