一、openssh

当主机开启了openssh服务,那么就对外开放了远程连接的接口。

oppenssh服务的服务端  sshd

oppenssh服务的客户端  ssh

二、在服务端连接sshd的方式

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

例如linux远程服务openssh

连接ip为172.25.254.178的root用户,首次连接是会询问是否连接,并且建立.ssh/know_hosts文件,用来记录连接过的主机信息,进行此操作需要知道对方密码。按exit退出

注意:以上连接方式是不能打开远程主机的图形功能的如果需要打开远程主机图形功能需要输入 -X"
ssh -X [email protected]

cheese   打开摄像头

三、给ssh服务添加新的认证方式KEY认证

1、生成锁和钥匙

[[email protected] ~]# ssh-******         ##生成**的命令
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):    #保存加密字符的文件用默认
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):         #可以为空,如果想为空必须大于4位
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:
00:4f:b0:72:40:9f:a6:fb:91:86:d2:69:bc:7c:75:5f [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o o..          |
|   o *           |
|  . * o          |
|   =   .         |
|  .     S        |
| o + .. .   E    |
|. B +. . . .     |
| + +..    .      |
|  o..            |

+--------------+

linux远程服务openssh

2.加密ssh用户的认证
在服务端

ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id        ##加密命令
-i            ##指定**
/root/.ssh/id_rsa.pub    ##**
root            ##加密用户
172.25.254.178        ##主机ip

linux远程服务openssh

3、验证

解密文件传输到客户端

scp /root/.ssh/id_rsa  [email protected]:/root/.ssh/

linux远程服务openssh

在客户端

ssh [email protected]        #连接不需要密码

linux远程服务openssh


在服务端

rm -fr /root/.ssh/authorized_keys    ##当此文件被删除,客户端解密文件失效

linux远程服务openssh


在服务端

cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys    ##从新生成锁文件,解密文件功能恢复

linux远程服务openssh

四、sshd的安全配置

1.禁止原始认证方式

vim /etc/ssh/sshd_config

78 PasswordAuthentication no|yes    ##开启或关闭ssh的默认认证方式

linux远程服务openssh

48 PermitRootLogin no|yes        ##开启或关闭root用户的登陆权限

linux远程服务openssh

79 AllowUsers westos            ##用户白名单,当前设定是只允许westos登陆

linux远程服务openssh

80 DenyUsers linux            ##用户黑名单,当前设定是只不允许linux登陆

linux远程服务openssh

2、控制ssh客户端访问

vim /etc/hosts.deny

sshd:ALL ##拒绝所有人链接sshd服务



相关文章:

  • 2021-05-14
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2021-12-11
  • 2021-05-30
  • 2021-12-18
  • 2021-04-30
猜你喜欢
  • 2021-05-14
  • 2021-06-12
  • 2021-07-13
  • 2021-09-02
  • 2022-01-06
  • 2022-12-23
  • 2021-06-09
相关资源
相似解决方案