使用xshell SSH远程连接 linux

确保网卡已配置

1.ping通外网,如果不能ping通,说明需要配置网卡。

2.查看你的网卡名,输入命令ip addr,我的网卡名为ifcfg-ens33

3.输入:vi /etc/sysconfig/netwoek-scripts/ifcfg-ens33

4.为了方便我这里设置动态网卡,将BOOTPROTO改为dhcp

5.输入systemctl restart network重启。

6.再次ping,若ping通,则说明可以连接。

安装openssh

使用xshell SSH远程连接 linux
可以看到我的虚拟机上已经提前安装好了openssh,若没有安装,可输入下面的命令。

yum install openssh

配置服务

输入vim /etc/ssh/sshd_config 在末尾添加以下两个参数
使用xshell SSH远程连接 linux
发现root下没有.ssh 使用xshell SSH远程连接 linux
输入ssh-******使用xshell SSH远程连接 linux
之后,我们输入ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]你的ip地址
使用xshell SSH远程连接 linux
最后我们发现生成了四个文件authorized_keys id_rsa id_rsa.pub known_hosts

启动服务

使用xshell SSH远程连接 linux
我们可以看到服务已启动且开机自启动,若没有启动请输入

systemctl start sshd

systemctl enable sshd 设置开启自启动

设置权限

只让文件的拥有者具有权限。

使用xshell SSH远程连接 linux

xftp连接linux获取id_rsa

使用xshell SSH远程连接 linux

按照上面的方式进行填写,若没有连接成功,多尝试几次,我在第一次连接的时候也没有成功,但相同的操作几分钟后就成功了。
使用xshell SSH远程连接 linux
之后我们双击id_rsa,这个文件就会传入到windows,我们在桌面上就能看到这个文件。
使用xshell SSH远程连接 linux

之后,我们关掉xftp。

xshell SSH登录

之后我们打开xshell 选择用public key方式登录,将id_rsa导入到用户**中,即可登录。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-52yQ6GxJ-1587294915079)(C:\Users\Denni\AppData\Roaming\Typora\typora-user-images\image-20200419191317423.png)]

成功

id_rsa导入到用户**中,即可登录。
使用xshell SSH远程连接 linux

成功

使用xshell SSH远程连接 linux