bash 如何避免在终端启动时总是为 id_rsa 输入密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40856905/
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-09-18 15:29:03  来源:igfitidea点击:

How to avoid always entering passphrase for id_rsa on terminal startup?

bashsshterminalssh-keyspassphrase

提问by HosseinK

Currently every time I start up terminal I get prompted the following:

目前,每次启动终端时,都会收到以下提示:

Last login: Mon Nov 28 21:32:16 on ttys000

Agent pid 2733

Enter passphrase for /Users/my_name/.ssh/id_rsa:

上次登录: 11 月 28 日星期一 21:32:16 在 ttys000

代理 pid 2733

为 /Users/my_name/.ssh/id_rsa 输入密码:

Could you please guide me on how I can avoid having to enter a passphrase everytime?

你能指导我如何避免每次都输入密码吗?

回答by Jules

You could add your passphrase to your keychain:

您可以将密码添加到您的钥匙串中:

ssh-add -K ~/.ssh/id_rsa

Or you can add it in your ~/.ssh/config:

或者您可以将其添加到您的~/.ssh/config

Host *
UseKeychain yes

回答by Jakuje

You probably wrote to your ~/.bashrclines

你可能写信给你的~/.bashrc台词

`eval ssh-agent`
ssh-add

or something like this. This means that it will start a new ssh-agentfor every shell you open, which is certainly not what you want. The agent should start when you open your Xsession (~/.xsession), or you should check if the agent is running before running a new one:

或类似的东西。这意味着它会ssh-agent为您打开的每个 shell启动一个新的,这肯定不是您想要的。代理应该在您打开 Xsession ( ~/.xsession)时启动,或者您应该在运行新代理之前检查代理是否正在运行:

[ -z $SSH_AUTH_SOCK ] && `eval ssh-agent` && ssh-add

回答by sjsam

You can use ssh-agent. The man-page says :

您可以使用ssh-agent. 手册页说:

ssh-agent is a program to hold private keys used for public key authenti‐ cation (RSA, DSA, ECDSA, Ed25519). ssh-agent is usually started in the beginning of an X-session or a login session, and all other windows or programs are started as clients to the ssh-agent program. Through use of environment variables the agent can be located and automatically used for authentication when logging in to other machines using ssh(1).

ssh-agent 是一个保存用于公钥认证的私钥的程序(RSA、DSA、ECDSA、Ed25519)。ssh-agent 通常在 X 会话或登录会话开始时启动,所有其他窗口或程序都作为 ssh-agent 程序的客户端启动。通过使用环境变量,可以定位代理并在使用 ssh(1) 登录其他机器时自动用于身份验证。

On further reading you can see :

在进一步阅读中,您可以看到:

The agent initially does not have any private keys. Keys are added using ssh-add(1). When executed without arguments, ssh-add(1) adds the files ~/.ssh/id_rsa, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ed25519 and ~/.ssh/identity. If the identity has a passphrase, ssh-add(1) asks for the passphrase on the terminal if it has one or from a small X11 programif running under X11. If neither of these is the case then the authenti‐ cation will fail. It then sends the identity to the agent. Several identities can be stored in the agent; the agent can automatically use any of these identities. ssh-add -l displays the identities currently held by the agent.

代理最初没有任何私钥。使用 ssh-add(1) 添加密钥。当不带参数执行时,ssh-add(1) 添加文件 ~/.ssh/id_rsa、~/.ssh/id_dsa、~/.ssh/id_ecdsa、~/.ssh/id_ed25519 和 ~/.ssh/identity。 如果身份有密码,ssh-add(1) 会在终端上询问密码,如果它有密码,或者来自一个在 X11 下运行的小型 X11 程序。如果这两种情况都不是,则身份验证将失败。然后它将身份发送给代理。代理中可以存储多个身份;代理可以自动使用这些身份中的任何一个。ssh-add -l 显示代理当前持有的身份。