您的位置:首页 > 运维架构 > Linux

创建公钥秘钥对,使用Public Key方式登录SSH(CentOS)

2014-09-18 09:14 459 查看
ssh-keygen -t rsa

输入你想创建的公钥的名字,也可以输入打开私钥的密码。一般不输入。

在当前目录能看到keipair,后缀为pub的是公钥。另外一个是私钥,在本地保存好。

把公钥上传到服务器的家目录,打开或者创建.ssh目录

cd ~/.ssh
mv ~/公钥.pub.pem authorized_keys
chmod 400 authorized_keys
cd ..
chmod 400 ./.ssh


然后修改sshd配置文件:
nano /etc/ssh/sshd_config

把其中的

PubkeyAuthentication no  改成 
PubkeyAuthentication yes
 PasswordAuthentication yes 改成

PasswordAuthentication no
注意前面的#号要去掉
重启sshd:
sudo service sshd restart

然后就可以使用private key远程登录了,不用输入密码
ssh -i yourkey.pem username@hostname
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息