Linux服务器 ssh免密登录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux服务器 ssh免密登录相关的知识,希望对你有一定的参考价值。

本文Linux系统为CentOS Linux 7。
?

?ssh-keygen命令生成公钥私钥,名字分别是“id_rsa.pub”和“id_rsa”,公钥发送到服务器上,私钥本地使用。

远程是在“~/.ssh/authrized_key”文件中,本地是在“%usersprofile%/.ssh/”目录

密钥生成命令
#ssh-keygen -t rsa

操作记录

[[email protected] ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ??密钥文件存储路径,直接回车使用默认
Created directory ‘/root/.ssh‘.
Enter passphrase (empty for no passphrase): ??密钥文件密码,直接回车使用不设置
Enter same passphrase again:
[[email protected] ~]# cd /root/.ssh/
[[email protected] .ssh]# ls
?id_rsa ? id_rsa.pub

密钥上传

使用“ssh-copy-id”命令上传
[[email protected] .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]‘s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh ‘[email protected]‘"
and check to make sure that only the key(s) you wanted were added.

使用其他工具将文件添加至authorized_keys文件末尾

上传 id_rsa.pub文件后,使用重定向符追加至authorized_keys文件末尾

[[email protected] .ssh]$ cat id_rsa.pub >> authorized_keys

[[email protected] .ssh]# cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAxxxxxAwmvid5q8naRwUohZTHYa/BVP0vxhdcav2TI0b4YRFIPdhd/kNprqV1HgQQQdbOdHwqMXepM68B+n8ukt7JFyfEF1IHML8hQy27hoJHwUo2fNJI8N8w5mO6glG+GxQciPP4dAJ+UAdd1qxtj3QKhYvRxxxxxoqDKOvkkvTp0brHz0vYDNV8Fx6MELMz4rSdcQPFZhSeZ9P5dJCcW6hdPBcUnKKMY8RtadPAPw+AGINexxxxxXbwEcqLxNRpW/DHG5E14Voxp4lgndeWOt8CJNWgWrp3mAYhf9sXvtICTdnhZA8Hjs0ckUV6tabfUlKsyj1gKEgSymP [email protected]

免密登录使用

命令行使用
将id_rsa拷贝至“%usersprofile%/.ssh/”目录,直接使用“ssh [email protected]”登录

技术分享图片

SecureCRT使用
?SecureCRT,新建会话,协议选择“ssh2”,其他根据实际情况填写,选中“PublicKey”,点击左侧的“Properties”,浏览生成的私钥保存。
?注意,使用私钥登录需要去掉“Password”前的勾。

技术分享图片
技术分享图片
技术分享图片

以上是关于Linux服务器 ssh免密登录的主要内容,如果未能解决你的问题,请参考以下文章

linux配置了免密,如何不使用免密登录

Windows ssh 免密登录

ssh免密登录linux服务器

linux下配置远程免密登录方法教程

Linux下配置ssh免密远程登录

linux上ssh免密登录原理及实现