如何在SSH代理中使用密码自动加载SSH密钥

时间:2018-08-12 12:44:26

标签: git ssh passphrase

每个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一起使用。)

1 个答案:

答案 0 :(得分:1)

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