1.背景介绍

平时我们都是通过输入账号和密码的方式登陆远程终端,那有没有其他的玩法呢?答案是:当然有!下面就介绍一种通过**的方式登陆SSH。

工具准备:一台电脑(推荐Win10),一台虚拟机(推荐VMware Workstation11),SSH登陆工具(xshell,securecrt,putty,推荐xshell),Linux系统(RedHatCentOS,debian,Ubuntu,推荐centos7.3)。

下面开始动手操作。

2.实验步骤

假设你已经通过ssh工具登陆上了linux终端。

(1)生成公钥和私钥

ssh-****** -t rsa

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: ##重复密码

在/root/.ssh/目录下会生成两个文件,id_rsa为私钥,id_rsa.pub为公钥。私钥自己下载到本地电脑妥善保存,公钥则可以任意公开。

(2)下载私钥到windows

sz /root/.ssh/id_rsa

如果没有请安装软件包lrzsz(yum install -y lrzsz)

(3)导入公钥

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

(4)更改SSH配置文件

修改SSH 的配置文件/etc/ssh/sshd_config,找到下面3行:

#RSAAuthentication yes

#PubkeyAuthentication yes

#AuthorizedKeysFile .ssh/authorized_keys

将前面的#去掉后保存。重启SSH 服务,运行命令:systemctl restart sshd

(5)xshell配置(看图)

1.新建一个会话

SSH通过**登陆

2.选择身份验证方式

SSH通过**登陆

3.导入私钥

SSH通过**登陆

4.输入自己设定的密码

SSH通过**登陆

5.确定用户**

SSH通过**登陆

6.输入密码

SSH通过**登陆

7.选择相应的会话

SSH通过**登陆

8.成功登陆

SSH通过**登陆

(6)关闭SSH密码登陆

修改SSH的配置文件/etc/ssh/sshd_config,找到下面1 行:

PasswordAuthentication yes

修改为:

PasswordAuthentication no

重启SSH服务,并运行命令:

systemctl restart sshd

相关文章:

  • 2022-12-23
  • 2021-07-19
  • 2021-11-14
  • 2021-08-08
  • 2022-12-23
  • 2021-12-19
  • 2021-07-26
  • 2021-12-22
猜你喜欢
  • 2021-07-25
  • 2021-05-06
  • 2021-10-16
  • 2021-04-19
  • 2021-04-14
  • 2021-08-29
相关资源
相似解决方案