2

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

2
  • 2
    sudo changes your user to root, a user that probably doesn't have the same private/public keys as the user you're running git pull from. Commented Dec 13, 2015 at 3:16
  • if running in a docker container you might have to load your local ssh keys in the container as well Commented Sep 5, 2020 at 1:22

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.