公司的linux服务器,重要的我都限制了IP登录。个别没有限制IP的在日志里面老是看到有人在尝试暴力破解root密码。前两天刚抽空升级了所有服务器的Openssl和Openssh,顺便设置了SSH的密钥登录,并禁止使用密码登录。在SecureCRT客户端生成的公钥传到服务器,用ssh-keygen将公钥转换成为OpenSSH兼容的格式,在SecureCRT客户端使用私钥登录。需要注意的是SecureCRT使用的是SSH2格式的公钥,而OpenSSH是使用的OpenSSH格式的公钥。
标签存档: Openssl
SecureCRT使用密钥登录SSH服务器
1.使用SecureCRT创建私钥和公钥.
SecureCRT: Quick Connect -> Authentiation -> Public Key -> Properties -> Create Identity File -> DSA/RSA -> Set Passphrase -> Done
这个时候在指定目录会生成两个文件,例如,私钥my_rsa和公钥my_rsa.pub
2.linux服务器上建立.ssh目录,一般情况下,已经有这个目录
# mkdir /root/.ssh
# chmod 700 /root/.ssh
3.将公钥 my_rsa.pub 传到linux服务器,将SSH2兼容格式的公钥转换成为Openssh兼容格式# ssh-keygen -i -f Identity.pub >> /root/.ssh/authorized_keys2
# chmod 600 /root/.ssh/authorized_keys2
4.在SecureCRT里面设置登录模式为PublicKey,并选择刚刚创建的my_rsa文件作为私钥
5.重启Linux服务器上SSH服务器
#service sshd restart 或者 /etc/rc.d/init.d/sshd restart
6.由于已经设置了密钥登录,原来的密码登录就完全可以去掉
# vi /etc/ssh/sshd_config
Protocol 2 /仅允许使用SSH2
PubkeyAuthentication yes /*启用PublicKey认证
AuthorizedKeysFile .ssh/authorized_keys2 /*PublicKey文件路径
PasswordAuthentication no /*禁止密码验证登录
PS:以上步骤是使用SecureCRT生成的密钥对来进行登录验证的,其实也可以在服务器上使用ssh-keygen命令生成的密钥,同样在生成密钥对之后,将格式转换成SecureCRT 使用的SSH2格式
升级Openssh
1. 升级OpenSSL
- 下载地址:http://www.openssl.org
- 如果使用0.9.8版本,在编译安装的时候会出错,虽然有办法可以解决…建议还是用0.9.7
# cd /usr/local/src
# tar xzvf openssl-0.9.7k.tar.gz
# cd openssl-0.9.7k
# ./config –prefix=/usr/local/openssl-0.9.7k
# make
# make test
# make install
2. 升级OpenSSH
# cd /usr/local/src
# tar xzvf openssh-4.3p2.tar.gz
# cd openssh-4.3p2
# ./configure \
–prefix=/usr \
–with-pam \
–with-zlib \
–with-ssl-dir=/usr/local/openssl-0.9.7k \
–with-md5-passwords \
–mandir=/usr/share/man \
–sysconfdir=/etc/ssh
# make
# make install
完成后,检查一下ssh是否升级成功
# ssh -v
OpenSSH_4.3p2, OpenSSL 0.9.7k 05 Sep 2006