bash脚本以自动化git拉力
我想自动从git中拉出。由于某些原因,无法在我使用的服务器中自动化密码内容。因此,需要通过bash文件完成。现在我的bash编码不太好。然后可以输入SSH键的密码。但是我真的不知道该怎么办...
#!/bin/bash 光盘 。 public_html/auto_deploy/foldername&& git fetch -all&& git Checkout -force“ Origin/Master”
以上无法使用...然后它需要输入密码,我不知道该怎么办...我该怎么做?
I want to automatically pull from Git. For some reasons it is not possible to automate the password thing in the server I am using. So it needs to be done by a Bash file. Now my Bash coding is not that good. Then it is possible to enter the passphrase for the SSH key. But I have really no clue what to do...
#!/bin/bash
cd . public_html/auto_deploy/foldername && git fetch --all && git checkout --force "origin/master"
The above is not working... And then it needs to enter the passphrase, and I have no idea what to do then... How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
幸运的是,根据核心 git文档,您可以将以下命令用于保存您的凭据以供以后使用 - 而不是在提示时每次键入。
以检查: git corterentials
Fortunately and according to the core Git documentation, you can use the following command to save your credentials for later on use - instead of typing it each time when prompted.
Interesting to check: Git Credentials
如果您想从shell脚本中拉出git,则需要这样使用:
If you want to do Git pull from a shell script, you need to use it like this:
您还可以使用
ssh-keygen
生成ssh键,并使用ssh://
方法git plup
。SSH键使您可以建立安全的连接。
在生成SSH键之前,请检查您的系统是否已经通过运行
cat〜/.ssh/id_rsa.pub
来检查系统。如果您看到一个以ssh-rsa
或ssh-dsa
开始的长字符串,则可以跳过ssh-keygen
sptep。要生成新的SSH键,只需打开您的终端并使用下面的代码即可。
ssh-keygen
命令提示您查找位置和文件名存储密钥对和密码。当提示位置和文件名提示时,您可以按Enter使用默认值。最好的做法是使用SSH键的密码,但不是必需的,您可以跳过通过按Enter来创建密码。请注意,您选择的密码无法更改或检索。使用下面的代码显示您的公钥。
复制您的用户配置文件的密钥。请从ssh-- 开始复制完整的键,然后以用户名和主机结尾。
You can also generate ssh keys using
ssh-keygen
and use thessh://
method togit pull
.SSH key allows you to establish a secure connection.
Before generating an SSH key, check if your system already has one by running
cat ~/.ssh/id_rsa.pub
. If you see a long string starting withssh-rsa
orssh-dsa
, you can skip thessh-keygen
step.To generate a new SSH key just open your terminal and use code below. The
ssh-keygen
command prompts you for a location and filename to store the key pair and for a password. When prompted for the location and filename you can press enter to use the default. It is a best practice to use a password for an SSH key but it is not required and you can skip creating a password by pressing enter. Note that the password you choose here can't be altered or retrieved.Use the code below to show your public key.
Copy-paste the key to your user profile. Please copy the complete key starting with
ssh-
and ending with your username and host.