1、root用户登陆后,运行以下第一句指令,其他根据提示进行输入:

[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
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:
99:46:6d:14:b1:92:9c:48:ab:d8:d7:3c:02:fd:12:8a root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|      .   +o     |
|     o + = .     |
|    . = * +      |
|   + + * =       |
|  E + + S        |
|     . + .       |
|                 |
|                 |
|                 |
+-----------------+

       此时在/root/.ssh/目录下生成了2个文件,id_rsa为私钥,id_rsa.pub为公钥。私钥自己下载到本地电脑妥善保存(丢了服务器可就没法再登陆了),为安全,建议删除服务器端的私钥。公钥则可以任意公开。

2、使用以下命令将公钥导入到系统中:

[root@localhost ~]# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys 

3、修改SSH的配置文件/etc/ssh/sshd_config :


RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

#默认PasswordAuthentication 为yes,即允许密码登录,改为no后,禁止密码登录
PasswordAuthentication no 

4、保存后重启SSH服务。

[root@localhost ~]# systemctl restart sshd.service

5、使用私钥登录

      SecureCRT使用私钥远程登录Linux。

                 打开“会话选项”,在“鉴权”选择“属性”,

                     

 在"会话设置",“使用身份或证书文件(E)”,选择生成的私钥,点确定。

                   

                 输入“通过短语”,点确定。

                  

Xshell5登录

  • 在“会话”窗口中新建会话,输入名称,和主机IP,点确定

  • 在“会话”窗口中点“连接”

  • 输入用户名

  • 在Public key 中选择生成的私钥,密码输入“passphrase"

  • 点“确定”,登录成功。

WinScp登录

1,在新建站点中,输入主机名,然后点"高级(A)..."

2,选择生成的私钥文件“id_rsa”,弹出将OpenSSH私钥转为Putty格式。点“确定”

3,输入"Passphrase","确定"保存转换后的密钥

 4,保存新建的会话

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:1 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐