python git 密码_Gitpython ssh密码

如果你想完全控制SSH连接的方式,并且你使用的是git 2.3或更新版本,你可以使用GIT_SSH_COMMAND环境变量集来实例化git。它指向一个名为的脚本,代替了ssh的。因此,您可以确定是否需要密码,并启动其他GUI以获取所需的输入。

在代码中,它会是这个样子:

remote_repo = self.repo.remotes[remote]

# here is where you could choose an executable based on the platform.

# Shell scripts might just not work plainly on windows.

ssh_executable = os.path.join(rw_dir, 'my_ssh_executable.sh')

# This permanently changes all future calls to git to have the given environment variables set

# You can pass additional information in your own environment variables as well.

self.repo.git.update_environment(GIT_SSH_COMMAND=ssh_executable)

# now all calls to git which require SSH interaction call your executable

remote_repo.push(self.repo.active_branch.name)

请注意,这只适用于通过SSH访问资源。例如,如果协议是HTTPS,则可能会提供密码提示。

在git 2.3之前,您可以使用GIT_SSH环境变量。它的工作方式不同,因为它只包含ssh程序的路径,其中会传递附加参数。当然,这可能是您的脚本,与上面显示的类似。我想更准确地指出这两个环境变量之间的差异,但我缺乏这样做的个人经验。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值