I am trying to overcome some limitations in our environment to write up an authorized SSH file for passwordless ssh keys.
I am requiring to perform an ssh as a to a target system, and then run a "sudo su -
, and then update the service account authorized_keys with a key"
This eventually has to go onto my ansible scripts.
I am using "ssh -t user@target
"sudo su - service-user
" - which actually successfully gets me into a shell for service-user. But I am not able to figure out a way to pass along the file modify commands with the above.
Any tips or alternative options?
Note: I need to use "ssh -t
" option as the requiretty is not set on target systems.
Cheers!
sudo su - service-user
is a bit overkill: it runs thesu
command as root just to drop down again to a different user. If you want an interactive session, you can get the same effect withsudo -iu service-user
. This may allow you to tighten up the sudoers file a bit too. – Tom Shaw Jul 22 '16 at 8:30