StrictHostKeyChecking no
UserKnownHostsFile /dev/null
######## ansible中取消ssh交换式yes/no ########
配置文件/etc/ansible/ansible.cfg的 [defaults] 中(打开注释)
# uncomment this to disable SSH key host checking
host_key_checking = False
######## ssh只允许使用key登录, 禁止使用密码登录 ########
1) 生产公私钥文件
# ssh-keygen -t rsa
上面命令一路回车, 此时在/root/.ssh/目录下生成了2个文件,id_rsa为私钥,id_rsa.pub为公钥。
私钥自己下载到本地电脑妥善保存(丢了服务器可就没法再登陆了),为安全,建议删除服务器端的私钥。公钥则可以任意公开。
使用以下命令将公钥导入到系统中:
# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
2) 修改SSH的配置文件/etc/ssh/sshd_config
# vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#默认PasswordAuthentication 为yes,即允许密码登录,改为no后,禁止密码登录
PasswordAuthentication no
3) 重启SSH服务
# /etc/init.d/sshd restart
4) 使用私钥登录xshell或securecrt客户端了
######## SSH服务启动报错案例 ########
在某台服务器上部署了sftp服务,最后发现sftp远程登录正常,但是ssh远程登录失败(尽管已经输入了正确的用户名和密码)。
1[root@kevin ssh]# service sshd restart 2Stopping sshd: [ OK ] 3Starting sshd: 4/etc/ssh/sshd_config line 81: Unsupported option GSSAPIAuthentication/etc/ssh/sshd_config line 83:Unsupported option GSSAPICleanupCredentials 5 Starting sshd: [ OK ] 6 7如上启动后,远程ssh登录这台机器,输入正确的用户名和密码,则会登录失败!! 8 9[root@kevin ssh]# ssh -V 10OpenSSH_7.6p1, OpenSSL 1.0.1e-fips 11 Feb 2013 11 12原因是新版本的openssh不支持以上参数,需要修改sshd的配置文件。 13修改内容如下,否则还是无法通过ssh登录这台服务器: 14[root@kevin ssh]# vim /etc/ssh/sshd_config 15....... 16##去掉前面的注释,允许root通过ssh登录 17PermitRootLogin yes 18##注释掉下面三个参数 19#GSSAPIAuthentication yes 20#GSSAPICleanupCredentials yes 21#UsePAM yes 22 23再次重启ssh,上面的报错信息就没有了。此时远程ssh登录就OK了! 24[root@kevin ssh]# service sshd restart 25Stopping sshd: [ OK ] 26Starting sshd: [ OK ]