macos SVN+SSH,不用每次都做ssh-add?(苹果系统)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1909651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:36:44  来源:igfitidea点击:

SVN+SSH, not having to do ssh-add every time? (Mac OS)

svnmacosssh

提问by James J

I know the answer is out there, but I'm pretty Unix-dumb and probably wouldn't recognize the solution if it hit me in the face.

我知道答案就在那里,但我对 Unix 很笨,如果它击中我的脸,可能无法识别解决方案。

I'm on a Mac, connecting to a SVN server via SSH tunneling. I have to ssh-add privateKey.txtevery time I want to connect to the SVN server (Both Cornerstone and Xcode are connecting to SVN).

我在 Mac 上,通过 SSH 隧道连接到 SVN 服务器。我要ssh-add privateKey.txt我要连接到SVN服务器的每次(两个基石和Xcode中被连接到SVN)。

Is there a way to "save" the key somewhere so I don't have to do this every time? Add it to my Keychain? Some config file? Start up script?

有没有办法在某处“保存”密钥,这样我就不必每次都这样做?将它添加到我的钥匙串?一些配置文件?启动脚本?

回答by Nicholas Riley

First, move your private key file into ~/.ssh. This is not strictly necessary but it's the standard place for such things.

首先,将您的私钥文件移动到~/.ssh. 这不是绝对必要的,但它是此类事情的标准场所。

Then run ssh-add -K ~/.ssh/privateKey.txt. It'll prompt for your passphrase if necessary, then add it to your Keychain.

然后运行ssh-add -K ~/.ssh/privateKey.txt。如有必要,它会提示您输入密码,然后将其添加到您的钥匙串中。

After that, you shouldn't have to do anything else. A slightly longer explanation is available here.

在那之后,你不应该做任何其他事情。稍长的解释,请点击这里

回答by Adam

Storing Passphrases in the Keychain

在钥匙串中存储密码

To store the passphrase for your default key in the Keychain open a Terminal and run:

要在钥匙串中存储默认密钥的密码,请打开终端并运行:

ssh-add -K

And to store the passphrase for a different key run:

并为不同的密钥运行存储密码:

ssh-add -K /path/to/private/key/file

When prompted for your passphrase enter it and that is it.

当提示您输入密码时,输入它,就是这样。

You will never need to run ssh-add nor enter your passphrase again.

您将永远不需要运行 ssh-add 或再次输入您的密码。

Answer taken from this site: http://www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html

来自本网站的答案:http: //www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html

回答by mitalia

After much exploration, I think I've found the answer to this issue completely. First, make sure you do ssh-add -K ~/.ssh/your_key_here. This adds the key to your keychain. Some places, I have read that this is enough, but I wasn't certain. This is also mac-specific, so if you need to do this on another unix flavor, you won't have this option necessarily.

经过多次探索,我想我已经完全找到了这个问题的答案。首先,确保你这样做ssh-add -K ~/.ssh/your_key_here。这会将钥匙添加到您的钥匙串中。有些地方,我读到这已经足够了,但我不确定。这也是特定于 mac 的,因此如果您需要在另一种 unix 版本上执行此操作,则不一定有此选项。

For good measure, I edited the ~/.ssh/configfile (you may have to create it) to point to all the keys I have. Mine has the following:

为了更好地衡量,我编辑了~/.ssh/config文件(您可能必须创建它)以指向我拥有的所有密钥。我的有以下几点:

IdentityFile ~/.ssh/identity
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/id_dsa 
IdentityFile ~/.ssh/my_other_identity_here
IdentityFile ~/.ssh/yet_another_identity_here

According to the man pagefor ssh_config, it will try these in order. I'm not sure if the first three default ones I have listed need to be there, but I have included them anyway.

根据ssh_config的手册页,它将按顺序尝试这些。我不确定我列出的前三个默认值是否需要在那里,但我已经包括了它们。

回答by Ben

Since macOS 10.12.2 you can use the UseKeychainoption. Read more hereor look into man ssh_config.

从 macOS 10.12.2 开始,您可以使用该UseKeychain选项。 在此处阅读更多信息或查看man ssh_config.

     UseKeychain
         On macOS, specifies whether the system should search for passphrases in the user's keychain
         when attempting to use a particular key. When the passphrase is provided by the user, this
         option also specifies whether the passphrase should be stored into the keychain once it has
         been verified to be correct.  The argument must be ``yes'' or ``no''.  The default is ``no''.

So just do the following:

所以只需执行以下操作:

echo "UseKeychain yes" >> ~/.ssh/config

echo "UseKeychain yes" >> ~/.ssh/config

回答by viraptor

I don't have much experience with macs, so not sure if this version is ok for your, but have a look at http://www.phil.uu.nl/~xges/ssh/

我对 mac 没有太多经验,所以不确定这个版本是否适合你,但看看http://www.phil.uu.nl/~xges/ssh/

If this particular app doesn't work, that's what you're looking for anyways - ssh agent. On unix-like boxes, you'd want to start your whole window manager through that, to get the global effect, but it might not be possible in osx.

如果此特定应用程序不起作用,那么无论如何这就是您要寻找的 - ssh agent。在类 Unix 的盒子上,您希望通过它启动整个窗口管理器,以获得全局效果,但在 osx 中可能无法实现。

Some more info: http://www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html

更多信息:http: //www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html

回答by meduz

sshkeychainis one possibility. installs fine with macports using:

sshkeychain是一种可能性。使用 macports 安装得很好:

sudo port install sshkeychain

it uses the keychain to store passwords, and you may simply launch it at the start-up of your login session (using at the first launch the usual right-ght click in the dock's icon + "launch at startup")

它使用钥匙串来存储密码,您可以简单地在登录会话启动时启动它(在第一次启动时使用通常右键单击 Dock 的图标 +“启动时启动”)

Note that Apple's svn uses keychain to store passwords but not necessarily the svn binary you would build with macports.

请注意,Apple 的 svn 使用钥匙串来存储密码,但不一定是您将使用 macports 构建的 svn 二进制文件。

回答by Jakub Kukul

Add your key to the keychain by running:

通过运行将您的钥匙添加到钥匙串:

ssh-add -K ~/.ssh/id_rsa

and edit your ssh config (~/.ssh/config) file to automatically load keys from the key chain to the ssh-agent (AddKeysToAgent yesoption) and store passphrases in the keychain (UseKeychain yesoption):

并编辑您的 ssh 配置 ( ~/.ssh/config) 文件以自动将密钥从AddKeysToAgent yes钥匙串加载到 ssh-agent (选项) 并将密码存储在钥匙串 (UseKeychain yes选项 ) 中:

Host *
 AddKeysToAgent yes
 UseKeychain yes