Linux_入门 远程连接访问主机

1.openssh-server

功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

2.客户端连接方式

ssh    远程主机用户@远程主机ip
[[email protected] ~]# ssh [email protected]
The authenticity of host '172.25.0.11 (172.25.0.11)' 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)? yes    ##连接陌生主机时需要建立认证关系
Warning: Permanently added '172.25.0.11' (ECDSA) to the list of known hosts.
[email protected]'s password:                 ##远程用户密码
Last login: Mon Oct  3 03:13:47 2016
[[email protected] ~]#                    ##登陆成功

ssh 远程主机用户@远程主机ip -X                ##调用远程主机图形工具
ssh     远程主机用户@远程主机ip        command        ##直接在远程主机运行某条命令


Linux_入门 远程连接访问主机

3.sshkey加密

1.生成公钥私钥

[[email protected] ~]# ssh-******      ####生成公钥私钥工具
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):                   ######加密字符保存文件(建议用默认)
Enter passphrase (empty for no passphrase):                              ##**密码,必须>4个字符
Enter same passphrase again:                                                     ##确认密码
Passphrases do not match.  Try again.                                        ###两次输入不匹配
Enter passphrase (empty for no passphrase):
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:
43:c5:1b:27:79:64:31:8b:4e:08:c1:19:fe:c3:0b:58 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|     .++ ..o=.   |
|     .o. o=ooo   |
|      E o o*.    |
|     o + o.      |
|    . . S .      |
|       . +       |
|        .        |
|                 |
|                 |
+-----------------+



Linux_入门 远程连接访问主机

id_rsa        ##私钥,就是钥匙
id_rsa.pub    ##公钥,就是锁

2.添加key认证方式

Linux_入门 远程连接访问主机

3.分发钥匙给client主机

Linux_入门 远程连接访问主机

4.测试

Linux_入门 远程连接访问主机

4.提升openssh的安全级别

1.openssh-server配置文件

/etc/ssh/sshd_config
78 PasswordAuthentication yes|no        ##是否开启用户密码认证,yes为支持no为关闭
48 PermitRootLogin yes|no            ##是否允许超级用户登陆
49 AllowUsers student westos            ##用户白名单,只有在名单中出现的用户可以使用sshd建立shell
50 DenyUsers westos                ##用户黑名单

2.控制ssh客户端访问

vim /etc/hosts.deny
sshd:ALL        ##拒绝所有人链接sshd服务

vim /etc/hosts.allow
sshd:172.25.254.250    ##允许250主机链接sshd

sshd:172.25.254.250, 172.25.254.180    ##允许250和180链接

sshd:ALL EXCEPT 172.25.254.200        ##只不允许200链接sshd


3.ssh登陆提示修改该

vim /etc/motd        ##显示登陆后字符

hello world        ##在登陆后就会显示这个字符

Linux_入门 远程连接访问主机