如何在 Ubuntu 上使用 ssh-add 永久添加私钥? [英] How to permanently add a private key with ssh-add on Ubuntu?

查看:25
本文介绍了如何在 Ubuntu 上使用 ssh-add 永久添加私钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用密码保护的私钥,可以通过 SSH 访问服务器.

I have a private key protected with a password to access a server via SSH.

我有 2 台 linux (ubuntu 10.04) 机器,它们的 ssh-add 命令的行为是不同的.

I have 2 linux (ubuntu 10.04) machines and the behavior of ssh-add command is different in both of them.

在一台机器上,一旦我使用ssh-add .ssh/identity"并输入我的密码,密钥就被永久添加了,即每次我关闭计算机并再次登录时,密钥已经添加了.

In one machine, once I use "ssh-add .ssh/identity" and entered my password, the key was added permanently, i.e., every time I shutdown the computer and login again, the key is already added.

在另一个中,我每次登录时都必须添加密钥.

In the other one, I have to add the key every time I login.

据我所知,我对两者都做了同样的事情.唯一的区别是密钥是在永久添加的密钥上创建的.

As far as I remember, I did the same thing on both. The only difference is that the key was created on the one that is added permanently.

有谁知道如何将它永久添加到另一台机器上?

Does anyone know how to add it permanently to the other machine as well?

推荐答案

一个解决方案是强制永久保留密钥文件,方法是将它们添加到您的 ~/.ssh/config 文件中:

A solution would be to force the key files to be kept permanently, by adding them in your ~/.ssh/config file:

IdentityFile ~/.ssh/gitHubKey
IdentityFile ~/.ssh/id_rsa_buhlServer

如果您在 ~/.ssh 目录中没有config"文件,那么您应该创建一个.它不需要root权限,所以很简单:

If you do not have a 'config' file in the ~/.ssh directory, then you should create one. It does not need root rights, so simply:

nano ~/.ssh/config

...并根据您的要求输入上面的行.

...and enter the lines above as per your requirements.

为此文件需要有 chmod 600.您可以使用命令 chmod 600 ~/.ssh/config.

For this to work the file needs to have chmod 600. You can use the command chmod 600 ~/.ssh/config.

如果您希望计算机上的所有用户都使用密钥,请将这些行放入 /etc/ssh/ssh_config 并将密钥放入所有人都可以访问的文件夹中.

If you want all users on the computer to use the key put these lines into /etc/ssh/ssh_config and the key in a folder accessible to all.

此外,如果您想设置特定于一台主机的密钥,您可以在 ~/.ssh/config 中执行以下操作:

Additionally if you want to set the key specific to one host, you can do the following in your ~/.ssh/config :

Host github.com
    User git
    IdentityFile ~/.ssh/githubKey

当您有许多身份时,服务器不会因为您首先尝试错误的身份而拒绝您时,这具有优势.只会尝试特定的身份.

This has the advantage when you have many identities that a server doesn't reject you because you tried the wrong identities first. Only the specific identity will be tried.

这篇关于如何在 Ubuntu 上使用 ssh-add 永久添加私钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆