I wrote a shell script to do project releasing with Git
, in the shell script I first cd
to the Git working copy and then do git pull origin master
.
But it prompts me for password: git@localhost's password:
, this's annoying, and I'm wondering if I can indicate the password for git pull
in the script, like this:
git pull origin master --password abcd123
Any idea?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Generally: Don't put passwords into scripts and especially don't supply them with command arguments because that means they are published via the ps
command to anyone on the same computer.
The solution here is to use ssh and run an ssh agent. The agent loads your private key and supplies that to the shell script when it tries to connect to the remote side via SSH. That way, you only need to give your pass phrase to the agent.
This blog post should give you more details: Password-less logins with OpenSSH
If you're using Windows, putty comes with the same functionality.