git拉入bash脚本

时间:2015-12-13 03:10:32

标签: git bash

我尝试使用git pull运行bush脚本,但是Permission被拒绝。

执行命令

 sudo bash ./script.sh

脚本:

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

并且:

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!

访问ssh键的权利:

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

如何解决这个问题?

P.S。当我在终端中运行git pull origin master时 - 一切正常

1 个答案:

答案 0 :(得分:1)

SSH私钥400而不是600.(Chmod 400 id_rsa)。此外,您正在以sudo身份运行,这将破坏您的SSH路径。