【问题标题】:How to load automatically SSH keys with passphrases in SSH agent如何在 SSH 代理中使用密码短语自动加载 SSH 密钥
【发布时间】:2019-01-19 09:28:14
【问题描述】:

每个 git 存储库都有一个 SSH 密钥。我在 Bitbucket 和 Gitlab 上有存储库。我在 Ubuntu 18.04 LTS 下。如果我将这些密钥与ssh-add 一起使用,它可以工作,但我不想每次都使用ssh-add 我所有的密钥及其密码。我最多想在 Ubuntu 开始做一次。这是我配置中有趣的部分,我绝望地输入了/etc/ssh/ssh_config,以确保没有权利问题:

AddKeysToAgent yes

Host git@bitbucket.org:mysthiq/blog.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/Blog/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/guetzlifolder.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/GuetzliFolder/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/portfolio.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/portfolio/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/framework-cms.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/portfolio/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/medoucine.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/medoucine/cle-ssh-linux
    IdentitiesOnly yes

Host git@gitlab.wexample.com:oef/contests.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/vinalies1.3/cle-ssh-linux
    IdentitiesOnly yes

Host git@gitlab.wexample.com:oef/mobile_v1.3.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/oef/mobile/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/phpbench.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/phpbench/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/prevandcare.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/PrevAndCare/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/sfboilerplate.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/sfBoilerPlate/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/sitesize.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/SiteSize/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/vinalies.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/vinalies/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/vinalies1.3.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/vinalies1.3/cle-ssh-linux
    IdentitiesOnly yes

Host git@bitbucket.org:mysthiq/vinciaprep.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/vinciaprep/cle-ssh-linux
    IdentitiesOnly yes

Host git@gitlab.wexample.com:wexample-public/scripts.git
    UseKeychain yes
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/Wexample/cle-ssh-linux
    IdentitiesOnly yes

如果我能知道一种方法来快速测试我的 ssh 配置,而不必每次进行更改时都重新启动 ubuntu,我也会很高兴。 (目标是将这些项目与 PHPStorm 一起使用。)

【问题讨论】:

    标签: git ssh passphrase


    【解决方案1】:

    不是 100% 确定,但您的 SSH 代理需要知道用于该特定存储库的 SSH 密钥,并且由于安全问题,这不能是一个自动过程。要在每次运行此命令eval "$(ssh-agent -s)" 时使用不同的 SSH 密钥重新初始化它,然后为该存储库添加您的 SSH 密钥ssh-add <SSH-key-name>。使用这种方式,您无需重新启动机器。希望这会有所帮助。

    【讨论】:

    • 我现在已经使用了类似的命令,但我每天至少重启一次机器,因为这台机器不是服务器而是我的个人笔记本电脑,所以这对我没有帮助:)
    最近更新 更多