Drormat
Drormat

Reputation: 169

Git: how to $git pull [with password] on a command?

I created a Deployment shell script to preform $git pull for all of our websites, example :

#!/bin/bash

repo1=/var/www/html/website1
repo2=/var/www/html/website2

for repo in $repo1 $repo2
do
    (cd "${repo}" && git pull )
done

This is actually working but required to type password for any $git pull command. we have 10 websites stored on 4 servers ,so its a bit of an hassle to type the password 40 times.

Is there a simple way to add a password to the git pull command ?

for example:

$git pull -pw [password]

I know It's not the best and secured method but because I'm 1 of 2 persons authorized to access the servers , I don't really worry about someone revealing the password by watching Shell history.

Appreciate the help .

Upvotes: 0

Views: 1300

Answers (1)

Evans Belloeil
Evans Belloeil

Reputation: 2503

From : https://superuser.com/questions/338511/how-do-i-disable-password-prompts-when-doing-git-push-pull

Generate a private/public key pair for password-less authentication. For Linux, your keys are stored in ~/.ssh.

If you already have files in ~/.ssh that's named id_rsa and id_rsa.pub, then you already have a key pair. Append the contents of your public key (that's id_rsa.pub) to the Git repository's ~/.ssh/authorized_keys file.

$ scp ~/.ssh/id_rsa.pub [email protected]:id_rsa.tmp $ ssh [email protected] $ cat id_rsa.tmp >> .ssh/authorized_keys

If you don't have the key pair, generate one with

$ ssh-keygen -t rsa

Read this for further instructions: http://inchoo.net/tools-frameworks/how-to-generate-ssh-keys-for-git-authorization/

Upvotes: 2

Related Questions