bash脚本以自动化git拉力

发布于 2025-01-23 15:21:26 字数 295 浏览 0 评论 0原文

我想自动从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陈甜 2025-01-30 15:21:26

幸运的是,根据核心 git文档,您可以将以下命令用于保存您的凭据以供以后使用 - 而不是在提示时每次键入。

git config credential.helper store

使用此助手将存储未加密的密码在磁盘上,
仅受文件系统权限保护。此命令将无限期存储在磁盘上以供将来的Git程序使用。

您可能不想直接调用此命令;这是指
被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.

git config credential.helper store

Using this helper will store your passwords unencrypted on disk,
protected only by filesystem permissions. This command stores credentials indefinitely on disk for use by future Git programs.

You probably don’t want to invoke this command directly; it is meant
to be used as a credential helper by other parts of git

Interesting to check: Git Credentials

爱她像谁 2025-01-30 15:21:26

如果您想从shell脚本中拉出git,则需要这样使用:

git pull https://username:password@git_hostname.com/my/repository

If you want to do Git pull from a shell script, you need to use it like this:

git pull https://username:password@git_hostname.com/my/repository
尤怨 2025-01-30 15:21:26

您还可以使用ssh-keygen生成ssh键,并使用ssh://方法git plup

SSH键使您可以建立安全的连接。

在生成SSH键之前,请检查您的系统是否已经通过运行cat〜/.ssh/id_rsa.pub来检查系统。如果您看到一个以ssh-rsassh-dsa开始的长字符串,则可以跳过ssh-keygen sptep。

要生成新的SSH键,只需打开您的终端并使用下面的代码即可。 ssh-keygen命令提示您查找位置和文件名存储密钥对和密码。当提示位置和文件名提示时,您可以按Enter使用默认值。最好的做法是使用SSH键的密码,但不是必需的,您可以跳过通过按Enter来创建密码。请注意,您选择的密码无法更改或检索。

ssh-keygen -t rsa -C "$your_email"

使用下面的代码显示您的公钥。

cat ~/.ssh/id_rsa.pub

复制您的用户配置文件的密钥。请从ssh-- 开始复制完整的键,然后以用户名和主机结尾。

You can also generate ssh keys using ssh-keygen and use the ssh:// method to git 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 with ssh-rsa or ssh-dsa, you can skip the ssh-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.

ssh-keygen -t rsa -C "$your_email"

Use the code below to show your public key.

cat ~/.ssh/id_rsa.pub

Copy-paste the key to your user profile. Please copy the complete key starting with ssh- and ending with your username and host.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文