Avoid prompting password for git commands in ubuntu

922 Views Asked by At

I have set up ssh in my ubuntu server which I have installed git. So, I append my pubic key to the ~/.ssh/authorized_keys file of the server which git is installed. I can use any git commands from my local pc(where my public key is pasted in the ~/.ssh/authorized_keys)

Yet, I just wanted to know how do I avoid entering the password each time I use a git command. So that I can avoid entering the password each time. Thanks

1

There are 1 best solutions below

1
On

Response from https://askubuntu.com/questions/362280/enter-ssh-passphrase-once

Update: seems to be a bug from 13.10:

https://bugs.launchpad.net/ubuntu/+source/libpam-ssh/+bug/1247169

Anyway running the following commands the problem was fixed for me: How to fix

I fixed this by entering the following commands:

$ ssh-agent bash

This creates a new bash process that allows you to add private keys. When adding a new private key you will be prompted for the passphrase once and only once.

And then:

$ ssh-add /home/username/.ssh/id_rsa Enter passphrase for /home/username/.ssh/id_rsa:  Identity added:

/home/username/.ssh/id_rsa (/home/username/.ssh/id_rsa)

...where username is your username. You can do the same using $USER variable:

$ ssh-add /home/$USER/.ssh/id_rsa

And the problem was fixed.

Duplicate:

Git enter long passphrase for every push

Git keeps asking me for my ssh key passphrase

EDIT

The only way I know is to use something using expect

#!/usr/bin/expect -f
set timeout -1
spawn ssh -o PubkeyAuthentication=no host.example.com
expect -exact "Password: "
send -- "secret\r"
expect {\$\s*} { interact }

and probably deal with ssh-config's ProxyCommand or use python version which is more complex and allow keeping credentials in config file.

And as a note - the only acceptable solution (secure and convenient) is ssh keys based auth.