0

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 .

Drormat
  • 139
  • 2
  • 7
  • If you don't care about someone seeing the password in the history - why not _just_ add an ssh key and get rid of the need for a password completely? Users sharing accounts (implied) is the problem to solve here. – AD7six May 28 '14 at 09:06
  • Can you instruct me how to do it? For the record im running the shell script from windows on remotes using plink – Drormat May 28 '14 at 09:10
  • If you're only using passwords because you're not aware there's an alternative read up on how git uses ssh and ssh keys. For example [see this guide](https://help.github.com/articles/generating-ssh-keys), or the answer below. – AD7six May 28 '14 at 09:18
  • possible duplicate of [How to enter command with password for git pull?](http://stackoverflow.com/questions/11506124/how-to-enter-command-with-password-for-git-pull) – eis Jan 28 '15 at 15:49
  • you can see the answer on this other thread: https://stackoverflow.com/a/31835965/365237 – eis Jul 30 '19 at 18:47

1 Answers1

2

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 user@git.repo:id_rsa.tmp $ ssh user@git.repo $ 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/

Community
  • 1
  • 1
Evans Belloeil
  • 2,413
  • 7
  • 43
  • 76
  • I have done the direction above and now instead of _user@GitSource password_ , It requires _Enter passphrase for key '/home/dev/.ssh/id_rsa'_ – Drormat May 28 '14 at 13:44