为什么 github 在 git 推送文件到 /var/www/html 时询问用户名和密码?
Why github ask username and password when to git push files in /var/www/html?
我在.netrc
中设置了用户名和密码。
cat .netrc
machine github.com
login myname
password mypassword
- git 推送
/tmp
目录中的文件:
在 github 的网页中为此推送创建一个新的 repo test-tmp
。
sudo cp -R /var/www/html/cal /tmp
sudo chown -R debian.debian /tmp/cal
cd /tmp/cal
git init
git add *
git commit -m "Add file"
git remote add origin https://github.com/gitsnippet/test-tmp.git
git push origin master
Github不问用户名和密码,git push
成功。
- git 推送
/var/www/html/cal
目录中的文件:
在 github 的网页中为此推送创建一个新的 repo test-var
。
注意:所有的sudo
都不能省略,对于/var/www/html
中的文件,没有sudo
的git命令会出现如下错误
error: could not lock config file /var/www/html/cal/.git/config
: Permission denied.
sudo git init
sudo git add *
sudo git commit -m "Add file"
sudo git remote add origin https://github.com/gitsnippet/test-var.git
sudo git push origin master
现在 git集线器将询问用户名和密码:
Username for 'https://github.com': xxxx
Password for 'https://gitsnippet@github.com': xxxx
如何让githtb读取.netrc
中的用户名和密码,何时git推送/var/www/html
中的文件?
按 sudo
进行推送意味着:
- 不同的
git config
设置:检查 sudo git config credential.helper
(与 git config credential.helper
相比)
- 一个不同的
$HOME
(其中 sudo ls ~/.netrc 可能不存在)
确保这些资源(git config
和 .netrc
)存在于两个环境中。
sudo cp $HOME/.netrc /root/.netrc
我在.netrc
中设置了用户名和密码。
cat .netrc
machine github.com
login myname
password mypassword
- git 推送
/tmp
目录中的文件:
在 github 的网页中为此推送创建一个新的 repotest-tmp
。
sudo cp -R /var/www/html/cal /tmp
sudo chown -R debian.debian /tmp/cal
cd /tmp/cal
git init
git add *
git commit -m "Add file"
git remote add origin https://github.com/gitsnippet/test-tmp.git
git push origin master
Github不问用户名和密码,git push
成功。
- git 推送
/var/www/html/cal
目录中的文件:
在 github 的网页中为此推送创建一个新的 repotest-var
。
注意:所有的sudo
都不能省略,对于/var/www/html
中的文件,没有sudo
的git命令会出现如下错误error: could not lock config file
/var/www/html/cal/.git/config
: Permission denied.
sudo git init
sudo git add *
sudo git commit -m "Add file"
sudo git remote add origin https://github.com/gitsnippet/test-var.git
sudo git push origin master
现在 git集线器将询问用户名和密码:
Username for 'https://github.com': xxxx
Password for 'https://gitsnippet@github.com': xxxx
如何让githtb读取.netrc
中的用户名和密码,何时git推送/var/www/html
中的文件?
按 sudo
进行推送意味着:
- 不同的
git config
设置:检查sudo git config credential.helper
(与git config credential.helper
相比) - 一个不同的
$HOME
(其中 sudo ls ~/.netrc 可能不存在)
确保这些资源(git config
和 .netrc
)存在于两个环境中。
sudo cp $HOME/.netrc /root/.netrc