Apanasenko
Apanasenko

Reputation: 31

git pull into bash script

I try run bush script with git pull but have Permission denied.

Run:

 sudo bash ./script.sh

Script:

echo -n "Would you like to do 'git pull' (\"y\" or \"n\", default: \"n\"): "
read answer
if [ "$answer" = "y" ]; then
   if ! git pull origin master; then
      echo "Pull conflicts!"
      exit
   fi
fi

And have:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Pull conflicts!

Access right to ssh key:

drwx------ 2 ubuntu ubuntu 4096 Dec 13 02:32 .
drwxr-xr-x 8 ubuntu ubuntu 4096 Dec 13 02:05 ..
-rw------- 1 ubuntu ubuntu  390 Oct  8 07:13 authorized_keys
-rw------- 1 ubuntu ubuntu 1679 Dec 13 01:58 id_rsa
-rw-r--r-- 1 ubuntu ubuntu  405 Dec 13 01:58 id_rsa.pub
-rw------- 1 ubuntu ubuntu 1767 Dec 13 02:16 known_hosts

How fix this?

P.S. When I run git pull origin master in terminal - everything is OK

Upvotes: 2

Views: 472

Answers (1)

louahola
louahola

Reputation: 2136

SSH private keys 400 instead of 600. (Chmod 400 id_rsa). Also, you are running as sudo which will mess up your SSH path.

Upvotes: 2

Related Questions