开源的服务搭建,配置
比单个服务重要的,是学会搭建一个开源的思路
故障解决的思路
养成一个比较好的运维操作
对于一个陌生的开源服务,你就能顺序的搭建成功
二sshd服务安装-sshd 命令使用
SSHD 服务
介绍:SSH 协议安全外壳协议,为Secure Shell 的缩写 ,SSH 为建立在应用层和传输基础上的安全协议
作用: sshd 服务使用SSH 协议可以用来远程控制,或在计算机传递,文件
向比较之前Telnet 方式传输文件安全很多,因为Telnet 使用明文传输
是加密传递
服务安装
需要安装OpenSSH 四个安装包
openssh-5.3p1-114el6.7.x86_64
OpenSSH 软件包,提供了服务端后台程序,和客户端工具,用来加密远程控件和服务需要的核心文件
使用yum list all | grep openssh 查看
yum 安装
1 [root@localhost ~]# yum install openssh openssh-clients openssh-server -y
2 rpm 本地直接安装rpm 包文件
1) 启动服务[root@localhost ~]# systemctl start sshd
2) [root@localhost ~]# systemctl enable sshd 开机自启动
3)查看哪些是服务是开机自启动的
查看sshd 的服务状态
第一种登录方法
第二种方法
[root@localhost ~]# ssh -l root 192.168.24.170
ssh 防治暴力破解
1 ) 进入到 ssh
[root@localhost ~]# cd /etc/ssh/
2) [root@localhost ssh]# vim ssh_config
查看sshd 的端口
自己改动端口防治暴力破解
vim sshd_config
2)
3) 重新启动 sshd
systemctl restart sshd
4) 发现端口已经改变
使用-p 指定端口
ssh root@192.168.24.171 -p 3389
如果改了,密码也登陆不上
现在我们进行PrintMotd 提示信息
①[root@localhost ssh]# vim /etc/motd
② 插入以下内容
1 Warning ! From on,all of your operation has been record!
③
改端口
不允许密码登录,用秘钥登录
不允许root登录 直接登录
打印信息登录
注意看last登录信息
通过秘钥认证实现sshd认证
①
②
③
④
如果发现端口不是22 就可以使用一下复制
下载软件包
官方地址
http://www.fail2ban.com
1) 首先下载fail2ban 软件然后上传到linux 服务器
2) 解压 fail2ban 到/usr/local/
[root@localhost src]# tar -xf fail2ban-0.8.14.tar.gz -C /usr/local/
3 )[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
apache2 apr apr-util bin etc fail2ban-0.8.14
4) [root@localhost local]# cd fail2ban-0.8.14/
[root@localhost fail2ban-0.8.14]# ls
ChangeLog config doc fail2ban-server
5)
6)
7) 查看Python 的版本
8) 查看所有的Python的包
9) 进入到配置文件目录
[root@localhost fail2ban-0.8.14]# cd /etc/fail2ban/
10)[root@localhost fail2ban]# cd -
11)
12 ) 复制执行文件到 /etc/下的目录下
13)[root@localhost files]# cp redhat-initd /etc/rc.d/init.d/fail2ban
14)[root@localhost files]# chkconfig --add fail2ban
[root@localhost files]# cd ..
[root@localhost fail2ban-0.8.14]# pwd
/usr/local/fail2ban-0.8.14
快速查找
15 )[root@localhost fail2ban-0.8.14]# grep chkconfig ./* -R --color
./files/redhat-initd:# chkconfig: - 92 08
1)[root@localhost ~]# cd /etc/fail2ban/
2)[root@localhost fail2ban]# vim jail.conf
3 )改为如下图
4) 重启服务fail2ban
[root@xueshen65 fail2ban]# systemctl start fail2ban
5)
查看状态 已经启动
6 ) 谁知开机自启动状态
7) 再次查看状态
8) 查看防火墙
9)发现第四次就连接了不能输入密码了
10 ) 如何给自己放行
第一种方法 清空防火墙 IPtables -F
第二种方法
清空日志
①[root@xueshen65 ~]# cd /etc/fail2ban/
② cd action.d/
③ls
④[root@xueshen65 fail2ban]#vim iptables.conf
⑤
⑥ 保存
使用脚本来
第三种方法
使用denyhosts
[root@xueshen65 ~]# yum list all | grep denyhosts
pam 模块
1)
2 )[root@localhost pam.d]# vim sshd
3)
其他命令
使用公钥登录
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ll
total 8
-rw------- 1 root root 408 Apr 17 23:29 authorized_keys
-rw-r--r-- 1 root root 528 Apr 17 15:36 known_hosts
[root@localhost .ssh]# ls
authorized_keys known_hosts
4 ) 清空一下
把保存好的公钥复制到
5) authorized_keys 文件中
6)[root@localhost .ssh]# chmod 600 authorized_keys
7)[root@localhost .ssh]# vim /etc/ssh/sshd_config
8)
9) 重启sshd
systemctl restart sshd
10 ) 重新登录 发现 不要密码就可以登录