用root用戶,可以成功免密碼使用git進行push pull了。
新的專案名稱:newstart。
下面是root user的設(shè)定。
su root
ssh-keygen -t rsa -f /root/.ssh/id_rsa.github -P ''
將id_rsa.github.pub 貼到 ssh key 的githhub web page.
git config --global user.name "someone"
git config --global user.email "sbd@gmail.com"
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git
ssh -T git@github.com
git clone git+ssh://git@github.com/someone/newstart.git /tmp/newstart
Cloning into '/tmp/newstart'...
root user可以成功使用,一點問題沒有。
現(xiàn)在對一個普通用戶debian8
進行設(shè)置,剛才的設(shè)置全部重新設(shè)置了。
su debian8
ssh-keygen -t rsa -f /home/debian8/.ssh/id_rsa.github -P ''
這個key id_rsa.github.pub 貼到 ssh key in githhub web page.
git config --global user.name "someone"
git config --global user.email "sbd@gmail.com"
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git
#注意,在普通用戶下,無法使用config.
error: could not lock config file .git/config: Permission denied
sudo git config remote.origin.url git+ssh://git@github.com/someone/newstart.git
ssh -T git@github.com
Permission denied (publickey).
我通過-i 參數(shù),可以讓這個普通用戶連接上github.
ssh -i ./id_rsa.github.pub -vT git@github.com
You've successfully authenticated, but GitHub does not provide shell access.
可惜,連接上沒有用,無法clone.
git clone git+ssh://git@github.com/someone/newstart.git /tmp/newstart
Cloning into '/tmp/newstart'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
請問,如何針對一般用戶,對我的步驟進行修改?什麼原因會導(dǎo)致這樣的事情發(fā)生?
建議檢查一下你的HOME環(huán)境變量,可能是你之前修改過它,導(dǎo)致git找不到.gitconfig
了;另外,你可以檢查一下你的用戶主目錄下有沒有.gitconfig
,在你的用戶目錄下使用:
ls -a | grep .gitconfig
如果顯示沒有.gitconfig
,說明很可能是因為git在當(dāng)前用戶的主目錄下找不到gitconfig
。
或是你可以用locate
命令搜索一下.gitconfig
,
locate .gitconfig
如果很不幸,你用locate沒搜尋的話,那就使用updatedb
更新下locate資料庫吧,如果你的硬碟速度夠快的話,可以很快就完成。
sudo updatedb
當(dāng)然用find
指令也可以,但是速度比較慢:
sudo find / -name .gitconfig
上述操作有結(jié)果後,你看一下.gitconfig
文件的所在路徑是否是echo $HOME
的結(jié)果,如果不是,說明的確是你的$HOME環(huán)境變數(shù)的問題,建議將其重新設(shè)定成你的目前使用者主目錄的路徑。