centos免密码使用密钥登录
用密码登录总是不大安全的,最大的问题就是总是要修改密码,那么你能有多少密码呢,用密钥的话,隔断时间重新生成密钥,免去了想密码的烦恼。
基本方法是在客户端生成自己的私钥和密钥,将客户端生成的密钥传到服务端的密钥文件里,配置下服务器用密钥登录,就完成了。
以下以centos为服务器,客户端为windows,用putty
1.先用密码登录,在用户目录下建立目录.ssh,将此目录的权限设置为600,然后在此目录下建立一个新文件authrized_keys
[root@test1 .ssh]# chmod 600 authrized.keys ##这一部是必须的
2.配置服务器,去掉密码登录,使用密钥登录
vi /etc/ssh/sshd_configProtocol 2PasswordAuthentication noPubkeyAuthentication yes ##使用key登录AuthorizedKeysFile .ssh/authrized.keys ##key的名字
[root@test1 .ssh]# ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): ##直接回车Enter passphrase (empty for no passphrase): ##先不输入密码Enter same passphrase again: ##不输入密码Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:e0:21:b6:16:08:30:e2:c9:ad:a4:d0:be:00:b0:2f:ea root@test1.frady.info[root@test1 .ssh]# lsid_rsa id_rsa.pub##自动生成两个文件[root@test1 .ssh]# mv id_rsa.pub authrized.keys ##重命名密钥,保持和/etc/sshd/sshd_config里的名称一致