设置ssh使用密钥登陆
1、制作密钥对
[~] ssh-keygen // 建立密钥对 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): // 按 Enter Created 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. // 公钥 The key fingerprint is: 0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。
2、在服务器上安装公钥
[~] cd .ssh [.ssh] cat id_rsa.pub >> authorized_keys 为了确保连接成功,请保证以下文件权限正确 [.ssh] chmod 600 authorized_keys [.ssh] chmod 700 ~/.ssh
3、设置SSH,打开密钥登录功能,编辑/etc/ssh/sshd_config文件,进行如下设置:
[~] vim /etc/ssh/sshd_config RSAAuthentication yes PubkeyAuthentication yes 请留意root用户能否通过ssh登录: PermitRootLogin yes 当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录: PasswordAuthentication no 最后,重启ssh服务 [~] service sshd restart
4、配置SecureCRT使用公钥认证
1)、下载id_rsa私钥,id_rsa.pub公钥到本地(采用SecureCRT生成则忽略)
2)、在SecureCRT中,打开会话选项
3)、在“分类”(Category)中选择SSH2
4)、在右边的“身份验证(Authentication)”中选择“公钥(PublicKey)”
5)、点击旁边的“属性(Properites)”,选择“使用会话公钥设置(Use session public keysetting)”
6)、在“使用身份文件(Use identify file)”的输入框中,选择之前生成的id_rsa或者Identify
7)、注意:id_rsa和id_rsa.pub或者Identify和Identify.pub要保存在一起,并符合keyname和keyname.pub的对应格式
版权声明:本文由“憨小猪”发布,如需转载请注明出处。