闲来无聊,因为经常在openwrt上调试,而openwrt上的ssh server是叫做Dropbear,非常轻量级,所以想把Openssh server更换成Dropbear。
首先了解一下RSA/DSA:
- RSA 与 DSA 都是非对称加密算法。
- 基本上可以认为相同密钥长度的 RSA 算法与 DSA 算法安全性相当。
- ssh-dss 就是 DSA
- ssh-keygen的时候DSA密钥长度只能是1024,RSA没有限制,可以用2048
- Openssh 7.0及以上版本已经抛弃了DSA
- 比RSA和DSA更好的算法是有的,ECC(Elliptic Curves Cryptography):椭圆曲线算法。
- 在 ssh-keygen 中,ECC 算法的相应参数是"-t ecdsa"。
- 椭圆曲线算法只有在较新版本的 openssl 与 ssh-keygen 中才被支持
ok,一句话总结,现在最好用RSA 2048长度密钥,将来是ECC的天下。
安装dropbear
yum install dropbear
生成key:
dropbearkey -t <type> -f <filename> [-s bits]
-t type Type of key to generate. One of:
rsa
dss
ecdsa
-f filename Use filename for the secret key.
~/.ssh/id_dropbear is recommended for client keys.
-s bits Key size in bits, should be a multiple of 8 (optional)
DSS has a fixed size of 1024 bits
ECDSA has sizes 256 384 521
注意上面的语法: 推荐
dropbearkey -t rsa -s 2048 -f /etc/dropbear/dropbear_rsa_host_key
或者
dropbearkey -t ecdsa -s 521 -f /etc/dropbear/dropbear_ecdsa_host_key
修改xinetd
vi /etc/xinetd.d/ssh
service telnet
{
disable = no
flags = IPv4
socket_type = stream
wait = no
user = root
server = /usr/sbin/dropbear
server_args = -i -p22
}
重启xinetd
service xinetd restart
telnet localhost 22
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-dropbear_2015.67
...curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,kexguess2@matt.ucc.asn.aussh-rsa,ssh-dss=aes128-ctr,aes256-ctr,aes128-cbc,aes256-cbc,3des-ctr,3des-cbc=aes128-ctr,aes256-ctr,aes128-cbc,aes256-cbc,3des-ctr,3des-cbc;hmac-sha2-256,hmac-sha2-512,hmac-sha1-96,hmac-sha1,hmac-md5;hmac-sha2-256,hmac-sha2-512,hmac-sha1-96,hmac-sha1,hmac-md5zlib@openssh.com,nonezlib@openssh.com,none
这样就ok了。