一. openssh

1.让远程主机可以通过网络访问sshd服务,开始一个安全的shell
当主机中开启openssh服务,那么就对外开放了远程链接的接口
#openssh服务的服务端
sshd
#openssh服务的客户端
ssh

二. 在客户端连接sshd的方式
例如
ssh [email protected]   ##在客户端用ssh命令连接172.25.254.200


首先打开两个虚拟机
nm-connection-deitor 配置id

点击add
unit 8 openssh
点击create
unit 8 openssh
进行如下设置,设置完成后点击save

unit 8 openssh
unit 8 openssh
   
   
ip配置完成  

unit 8 openssh
ifconfig 查看ip
unit 8 openssh

服务端用同样的方法设置好后 输入ifconfig查看ip

unit 8 openssh

[[email protected] ~]# ssh [email protected]

The authenticity of host '172.25.254.200 (172.25.254.200)' can't be established.

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

Are you sure you want to continue connecting (yes/no)? ##当当前主机第一次连接陌生主机时

##会自动建立.ssh/know_hosts

##这个文中记录的是连接过的主机信息

[email protected]'s password: #输入密码连接成功

Last login: Fri Mar 30 02:05:52 2018 from 172.25.254.100

[[email protected] ~]# exit #表示退出当前连接

logout

Connection to 172.25.254.200 closed.

unit 8 openssh

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

ssh -X [email protected]

cheese

unit 8 openssh

在服务端建立文件

unit 8 openssh
远程连接删除文件

unit 8 openssh
文件被删除
unit 8 openssh

w -f 查看谁登陆过我
   unit 8 openssh
3. 给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..            |

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

unit 8 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.200 ##主机ip

3.验证

#解密文件传输到客户端

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

unit 8 openssh


unit 8 openssh

#在客户端

ssh [email protected]

**设置成功登陆不需要密码
unit 8 openssh


unit 8 openssh

#在服务端

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

 


unit 8 openssh

#在服务端

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

unit 8 openssh

#### 4.sshd的安全配置 ####

1.禁止原始认证方式

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

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

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

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

unit 8 openssh


unit 8 openssh

unit 8 openssh
unit 8 openssh


相关文章: