LINUX间SSH登录可以用公钥认证的方式(即SSH无密码登录),WINDOWS上也可以用公钥认证登录LINUX服务器。
可以用SecureCRT或者Putty创建,下面用SecureCRT演示。
SecureCRT--工具--创建公钥--密钥类型DSA--通行短语(比如123456)--密码长度1024(默认)--完成
把创建的公钥复制到LINUX服务器用户家目录上。我用的是SecureCRT自带的工具lrzsz。
mkdir .ssh
sudo chmod 700 .ssh
sudo cat Identity.pub >> .ssh/authorized_keys
sudo chmod 600 .ssh/authorized_keys
然后更改SSH的登录方式,启动证书,禁止使用密码登录。
sudo vi /etc/ssh/sshd_config
# Authentication:
LoginGraceTime 120 #限制用户登录验证时间
PermitRootLogin no #禁止root登录
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes #开启密钥认证
AuthorizedKeysFile %h/.ssh/authorized_keys #公钥存放默认路径
PermitEmptyPasswords no #禁止空密码
# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no #不允许密码验证
重新启动ssh,然后用SecureCRT测试
sudo /etc/init.d/ssh restart
SecureCRT--文件--连接--主机端口用户名--点击公钥属性--使用身份或证书文件--确定--连接--大功告成!
PS1:第一次连接需要输入通行密码,以后就不需要再输入通行密码了。少了输入SSH的帐号密码,是不是更安全些呢?
PS2:再限制IP访问SSH,服务器会更安全些。
vi /etc/hosts.allow
sshd:172.16.X.X:allow #在最后一行写入172.16.X.X/172.16.0(段)
vi /etc/hosts.deny
sshd:ALL
PS3:假设要删除公钥,在SECURECRT连接的时候不要选中公钥,然后进入SSH的配置文件修改如下:
1、注释#AuthorizedKeysFile %h/.ssh/authorized_keys
2、PasswordAuthentication yes
PS4:使用SecureCRT连接时提示:unable to authenticate using any of the configured authentication methods
解决:PasswordAuthentication yes