昨天看到了一个贴子,ssh被暴力破解了,所以就赶快把公司用的服务器上的ssh改成了密钥连接!
2011-07-14 10:42:33
1.在服务器上用ssh-keygen -t rsa -b 1024生成公钥和私钥
2.会你当前用户的home里生成两个文件
id_rsa 私钥
id_rsa.pub 公钥
3.修改sshd_config文件
Protocol 2 仅使用SSH2
ServerKeyBits 1024 将ServerKey强度改为1024比特
PermitRootLogin no 不允许用root进行登录
PasswordAuthentication no 不允许密码方式的登录
PermitEmptyPasswords no 禁止空密码进行登录
RSAAuthentication yes rsa用户验证
PubkeyAuthentication yes Pubkey用户验证
AuthorizedKeysFile .ssh/id_rsa.pub 公钥所在地
重起sshd就可以了,在这里要注意几点,修改sshd_config文件之前要备份,另外,如果修改后sshd起动失败了,服务又没在眼前,你可能就无法远程连接上服务器了。。。。
4.把生成的私钥copy到你的客户端电脑上,用putty的话,先用puttygen.exe把id_rsa 重新生成一下!
5.打开putty,设置一下,connection->ssh->auth->Private key for....那里选中刚才生成的私钥.
连接就行了!!