Linux学习笔记(7)
来源:互联网 发布:杀马特火星文 知乎 编辑:程序博客网 时间:2024/06/06 01:55
###1.openssh-server####
功能:让远程主机可以通过网络访问sshd服务,开启一个安全shell
####2.客户端连接方式####
ssh 远程主机用户@远程主机ip
[root@server2 ~]# ssh root@172.25.34.1
The authenticity of host '172.25.34.1 (172.25.34.1)' 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.34.1' (ECDSA) to the list of known hosts.
root@172.25.34.1's password: ##远程用户密码
Last login: Sun Jul 30 03:13:47 2017
[root@server1 ~]# ##登陆成功
ssh 远程主机用户@远程主机ip -X ##调用远程主机图形工具
ssh 远程主机用户@远程主机ip command##直接在远程主机运行某条命令
####3.sshkey加密####
1.生成公钥私钥
[root@server1 ~]# ssh-keygen ##生成公钥私钥工具
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):[enter] ##加密字符保存文件(建议用默认)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): [enter]##密钥密码,必须>4个字符
Enter same passphrase again: [enter]##确认密码
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:
ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 root@server1.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|o |
|E. |
|.. |
|. . o |
|.o. * . S |
|oo.o o . |
|+ =. . . |
|o. oo.+.. |
| ..o*. |
+-----------------+
[root@server1 ~]# ls /root/.ssh/
id_rsa id_rsa.pub
id_rsa ##私钥,就是钥匙
id_rsa.pub ##公钥,就是锁
2.添加key认证方式
[root@server1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.34.1
ssh-copy-id ##添加key认证方式的工具
-i ##指定加密key文件
/root/.ssh/id_rsa.pub ##加密key
root ##加密用户为root
172.25.34.1 ##被加密主机ip
3.分发钥匙给client主机
[root@server1 ~]# scp /root/.ssh/id_rsa root@172.25.34.2:/root/.ssh/
4.测试
[root@server2 ~]# ssh root@172.25.34.1 ##通过id_rsa直接连接不需要输入用户密码
Last login: Sun Jul 30 03:20:47 2017 from 172.25.34.2
[root@server0 ~]#
####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
sshd:all
50 DenyUsers westos ##用户黑名单
sshd:用户IP
vim /etc/hosts.deny
sshd:ALL ##拒绝所有人链接sshd服务
vim /etc/hosts.allow
sshd:172.25.34.3 ##允许server3主机链接sshd
sshd:172.25.34.2, 172.25.34.3 ##允许250和180链接
sshd:ALL EXCEPT 172.25.254.3 ##只不允许200链接sshd
3.ssh登陆提示修改该
hello world ##在登陆后就会显示这个字符
功能:让远程主机可以通过网络访问sshd服务,开启一个安全shell
####2.客户端连接方式####
ssh 远程主机用户@远程主机ip
[root@server2 ~]# ssh root@172.25.34.1
The authenticity of host '172.25.34.1 (172.25.34.1)' 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.34.1' (ECDSA) to the list of known hosts.
root@172.25.34.1's password: ##远程用户密码
Last login: Sun Jul 30 03:13:47 2017
[root@server1 ~]# ##登陆成功
ssh 远程主机用户@远程主机ip -X ##调用远程主机图形工具
ssh 远程主机用户@远程主机ip command##直接在远程主机运行某条命令
####3.sshkey加密####
1.生成公钥私钥
[root@server1 ~]# ssh-keygen ##生成公钥私钥工具
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):[enter] ##加密字符保存文件(建议用默认)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): [enter]##密钥密码,必须>4个字符
Enter same passphrase again: [enter]##确认密码
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:
ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 root@server1.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|o |
|E. |
|.. |
|. . o |
|.o. * . S |
|oo.o o . |
|+ =. . . |
|o. oo.+.. |
| ..o*. |
+-----------------+
[root@server1 ~]# ls /root/.ssh/
id_rsa id_rsa.pub
id_rsa ##私钥,就是钥匙
id_rsa.pub ##公钥,就是锁
2.添加key认证方式
[root@server1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.34.1
ssh-copy-id ##添加key认证方式的工具
-i ##指定加密key文件
/root/.ssh/id_rsa.pub ##加密key
root ##加密用户为root
172.25.34.1 ##被加密主机ip
3.分发钥匙给client主机
[root@server1 ~]# scp /root/.ssh/id_rsa root@172.25.34.2:/root/.ssh/
4.测试
[root@server2 ~]# ssh root@172.25.34.1 ##通过id_rsa直接连接不需要输入用户密码
Last login: Sun Jul 30 03:20:47 2017 from 172.25.34.2
[root@server0 ~]#
####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
sshd:all
50 DenyUsers westos ##用户黑名单
sshd:用户IP
黑名单先生效,白名单后生效。
在上面配置文件添加的黑白名单是针对本机用户
下面文件单独写的是对外来的sshd客户端的限制
vim /etc/hosts.deny
sshd:ALL ##拒绝所有人链接sshd服务
vim /etc/hosts.allow
sshd:172.25.34.3 ##允许server3主机链接sshd
sshd:172.25.34.2, 172.25.34.3 ##允许250和180链接
sshd:ALL EXCEPT 172.25.254.3 ##只不允许200链接sshd
3.ssh登陆提示修改该
vim /etc/motd ##显示登陆后字符
hello world ##在登陆后就会显示这个字符
阅读全文
0 0
- Linux学习笔记(7)
- linux学习笔记(7)
- Linux学习笔记(7)
- Linux学习笔记7
- Linux学习笔记7
- linux学习笔记7
- linux驱动学习笔记7
- linux驱动学习笔记7
- Linux学习笔记(7)-文件系统
- linux学习笔记(2)
- linux学习笔记(一)
- Linux学习笔记(一 )
- Linux学习笔记(二 )
- linux学习笔记(转)
- linux学习笔记(1)
- linux学习笔记(转)
- linux学习笔记(二)
- linux学习笔记(三)
- 23种设计模式(20)-状态模式
- C常用自定义函数集锦
- 详解python中的__new__方法
- SpringData中的PagingAndSortingRepository接口
- yii2-GridView在开发中常用的功能及技巧
- Linux学习笔记(7)
- C/C++中输入多组数据方法
- 使用数据库UNIQUE constraint failed
- Spring MVC与Struts2的区别
- 结合FlexboxLayout实现标签选择功能
- ionic3(一)安装和配置
- php判断密码强度
- js 中处理金额数据 四舍五入数据(,处理和保留小数处理)
- svn插件集成myeclipse2014的两种方式