Issue
I have user - dev
with ssh config like this:
Host *
IdentityFile ~/.ssh/id_rsa
If I login as this dev user (sudo su dev) and try to clone, everything works fine. Clone used without passphrase.
But when I use command like this:
sudo -u dev git clone repositoryurlhere
I always see:
Enter passphrase for key '/home/dev/.ssh/id_rsa'
How to get rid of this?
Solution
The file /home/dev/.ssh/id_rsa
is encrypted. You probably had to enter a passphrase a few minutes agon when you were still dev
, but forgot you did. After entering the password your keychain usually remembers it for a few minutes (similar to sudo
, you need to enter your password only every few minutes).
When you switched to another user and then used sudo -u dev
, that remembered password was gone and you had to re-enter the password.
The only solution is to remove the password from the identity file using
ssh-keygen -p -N "" -f /home/dev/.ssh/id_rsa
Afterwards you won't have to enter a password, neither as dev
nor when using sudo -u dev
.
Answered By - Nils Werner