I have an Ansible server with 3 ubuntu servers (hosts). So i want to be able to logon to those servers by typing in the SSH key password once. I have edited my .bashrc with an alias. alias ssha='eval $(ssh-agent) && ssh-add'

Whenever i login to the Ansible server and do:

foulan@ansible-server:~$ ssha
Agent pid 1396
Enter passphrase for /home/foulan/.ssh/id_ed25519:

If i typ in the password for the ssh-key, i'm able to login every server without prompting the password. But if i go after that in root mode by typing sudo su.

And again try to ssh in to one of my servers it asks me for me for the password.

But if i run ps aux | grep ssh

it still shows me that the ssh-agent in the back is running ??

I basically want to be able to ssh to any server in root mode without typing the pass everytime

Any help would be appreciated,

  • Not going to happen. Putting sudo aside for a minute (as that is not where your issue is) you are running su switch user. As soon as you run that you are a different user without your previous environment.. Note to mention the REALLY bad security practise. If you MUST log in as root ask for key based login to the root user. – Timothy c Oct 21 '20 at 21:28

Assign the user with passwordless sudo access. When user is logged-in will just do the following to elevate the privilege:

$ sudo su

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.