ssh 远程连接

在 linux 中 ssh 是一个网络服务,ssh 默认端口是 22 ,centos 中默认安装了

准备两个虚拟机:保证两个系统能够相互 ping 通

1.查看 ip 地址  ifconfig

  客户端:10.10.92.197

  服务端:10.10.92.202

2.测试是否能够相互连通

  客户端  ping  10.10.92.202

  服务端  ping  10.10.92.197

3.必须关闭防火墙和安全模式

  查看防火墙状态

  systemctl  status  firewalld

  关闭防火墙

  systemctl  stop  firewalld

  关闭安全模式

  setenforce  0

linux 停止服务

systemctl  stop  服务名

启动服务

systemctl  start  服务名

重启服务

systemctl  restart  服务名

查看服务的状态

systemctl  status  服务名

4.通过 ssh 链接

  使用客户端链接服务端

  ssh  服务端用户名@服务端的 ip 地址

  第一次链接时会出现提示

 是否加入白名单

链接成功后可以通过查看 ip 地址来判断当前在哪个电脑

查看登录日志

  more  /var/log/secure

  who /var/log/wtmp

使用 windows 链接服务器

  一般会使用一些软件 xshell

  运行软件


使用秘钥登录:

  客户端

  服务端

1.  客户端生成秘钥

  ssh-keygen  -t  rsa 

2.  将公钥改名字

  authorized_keys

3.  将改名字后的公钥上传到服务器

  将本地文件上传至服务器

  scp  要上传的文件  服务器用户名@服务器 ip:上传到服务端的路径

  将客户端公钥上传到服务端 root 用户下的 .ssh 目录下

4.  使用私钥链接服务

  通过客户端链接服务端

  ssh  -i  私钥地址  root@服务端 ip 地址

猜你喜欢

转载自www.cnblogs.com/pjcd-32718195/p/11732665.html