0.关于ssh最佳实践的基本认识
1)禁用默认端口,2)禁用版本 version 1,3)限制可登陆用户,使用白名单,4)限制空闲会话时长,5)防火墙设置ssh访问规则,6)限定监听的地址,7)使用强密码,8)基于秘钥认证,9)禁止空密码,10)禁止root登陆,11)限制频度和并发数,12)做好日志分析
1.关于白名单的使用。
在配置文件中增加AllowUsers,重新载入服务,创建白名单外的新用户进行测试,发现登陆时会被服务器拒绝。
[root@lab1 ~]# vim /etc/ssh/sshd_config
[root@lab1 ~]# grep AllowUsers /etc/ssh/sshd_config
AllowUsers root user001
[root@lab1 ~]# systemctl reload sshd.service
[root@lab1 ~]# useradd user002
[root@lab1 ~]# passwd user002
Changing password for user user002.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
这里还可以利用系统自动生成随机密码,具体方法如下:
[root@lab1 ~]# tr -dc A-Za-z0-9_ < /dev/urandom | head -c 30 | xargs
24WOWQoMVvdC_4zyULC7sQS_Y5kjmX
2.关于dropbear。
先安装开发工具和开发服务平台,下载dropbear代码包,解压缩后,阅读INSTALL文件。进入解压缩后的目录,使用 ./configure对环境进行解析和配置,使用make进行编译(这有PROGRAMS=参数),使用make install进行安装(这有PROGRAMS=参数)。注意:这里会提示没有发现zlib库(可能跟不同的版本有关系),上网下载zlib代码包,同样的解压缩后,在解压缩目录,使用 ./configure对环境进行解析和配置,使用make进行编译,使用make install进行安装。
安装完成后,会在/usr/local/sbin和/usr/local/bin目录下生成命令,创建/etc/dropbear目录,并尝试生成一个2048位的rsa密钥,也可以生成一个dss秘钥(不用指定位数),指定端口2202,尝试通过该端口登陆。也可以使用dbclient工具登陆其他服务器。
[root@lab1 ~]# yum groupinstall "Development Tools" "Server Platform Development" -y
[root@lab1 ~]# wget https://matt.ucc.asn.au/dropbear/releases/dropbear-2016.74.tar.bz2
[root@lab1 ~]# tar -xf dropbear-2016.74.tar.bz2
[root@lab1 ~]# cd dropbear-2016.74
[root@lab1 dropbear-2016.74]# less INSTALL
Basic Dropbear build instructions:
- Edit options.h to set which features you want.
- Edit debug.h if you want any debug options (not usually required).
(If using a non-tarball copy, "autoconf; autoheader")
./configure (optionally with --disable-zlib or --disable-syslog,
or --help for other options)
Now compile:
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
And install (/usr/local/bin is usual default):
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
(you can leave items out of the PROGRAMS list to avoid compiling them. If you
recompile after changing the PROGRAMS list, you *MUST* "make clean" before
recompiling - bad things will happen otherwise)
See MULTI for instructions on making all-in-one binaries.
If you want to compile statically, add "STATIC=1" to the make command-line.
Binaries can be stripped with "make strip"
============================================================================
If you're compiling for a 386-class CPU, you will probably need to add
CFLAGS=-DLTC_NO_BSWAP so that libtomcrypt doesn't use 486+ instructions.
============================================================================
INSTALL
[root@lab1 dropbear-2016.74]# ./configure