博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ubuntu设置 SSH 通过密钥对登录
阅读量:4552 次
发布时间:2019-06-08

本文共 1410 字,大约阅读时间需要 4 分钟。

1. 制作密钥对

首先在服务器上制作密钥对。登录到打算使用密钥登录的账户,然后执行以下命令:

[root@host ~]$ ssh-keygen  <== 建立密钥对Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 EnterCreated directory '/root/.ssh'.Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空Enter same passphrase again: <== 再输入一遍密钥锁码Your identification has been saved in /root/.ssh/id_rsa. <== 私钥Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥

密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。

现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。

2. 在服务器上安装公钥

键入以下命令,在服务器上安装公钥:

[root@host .ssh]$ chmod 600 authorized_keys[root@host .ssh]$ chmod 700 ~/.ssh

3. 设置 SSH,打开密钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置:

RSAAuthentication yesPubkeyAuthentication yes

另外,请留意 root 用户能否通过 SSH 登录:

PermitRootLogin yes

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

PasswordAuthentication no

最后,重启 SSH 服务:

[root@host .ssh]$ service sshd restart

4. 将私钥下载到客户端,然后转换为 PuTTY 能使用的格式

使用 、SFTP 等工具将私钥文件 id_rsa 下载到客户端机器上。然后打开 ,单击 Actions 中的 Load 按钮,载入你刚才下载到的私钥文件。如果你刚才设置了密钥锁码,这时则需要输入。

载入成功后,PuTTYGen 会显示密钥相关的信息。在 Key comment 中键入对密钥的说明信息,然后单击 Save private key 按钮即可将私钥文件存放为 PuTTY 能使用的格式。

今后,当你使用Xshell或 PuTTY 登录时,可以在左侧的 Connection -> SSH -> Auth 中的 Private key file for authentication: 处选择你的私钥文件,然后即可登录了,过程中只需输入密钥锁码即可。

转自:http://blog.csdn.net/permike/article/details/52386868

转载于:https://www.cnblogs.com/dudumao/p/7407370.html

你可能感兴趣的文章
CentOS7集群环境Elastic配置
查看>>
【EXCEL】指定の項目の内容一覧を表示
查看>>
Head first java chapter 4 对象的行为
查看>>
luogu_4503【题解】企鹅QQ 哈希
查看>>
linux 面试
查看>>
Linux:Gentoo系统的安装笔记(三)
查看>>
打开IE窗口并最大化显示
查看>>
Windows API SendMessage 和 PostMessage 内部实现
查看>>
服务器发送邮件出现Could not connect to SMTP host错误 解决办法
查看>>
sklearn.preprocessing.LabelBinarizer
查看>>
C teaching
查看>>
分隔指定内容,提取章节数
查看>>
this point
查看>>
leetcode 30 Substring with Concatenation of All Words
查看>>
验证登录信息是否合法
查看>>
线程池
查看>>
git版本控制器的基本使用
查看>>
Redis 笔记与总结4 set 和 zset 类型
查看>>
jQuery Ajax 回调函数中调用$(this)的问题 [ 转 ]
查看>>
thymeleaf:字符串拼接+输出单引号
查看>>