Linux配置公钥授权方式ssh连接

本地机

生成Key

1
2
ssh-keygen -t rsa
//passphrase务必为空

~/.ssh目录下生成私钥id_rsa和公钥id_rsa.pub

将公钥上传或复制到目标机 .ssh 目录下

1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDun/aN5lomQhxFn2dYfTOhMnemPJaeaAlaZv9Do2t5vH2KRr7PHv89swkjMC/HvD0oK+iJ66cAypotqnlizdJv487SWOfQplEa5e6PeIpXDvjeqiuyyb25vbX3Io7IeEli1DupZPjXjmahVf70etKUl5v2GettM3OOKewO4v+q4WabBvyfyrvwrqboX1fbO5j/X6gAPy7csu0tyrnEGG5D2R/KkrqIts1lpQ3fx3+wGqidfWDyGqa2e+XQ4l3E60534lB7pq8aACsJrgR5c500Uca9b53dpz8WWwXvfQuda2FFBR5SQ6jVu7jGupHQqOHZb3I/+I91ol4nxmJaDbJp yezhou@appblog-gateway

远程机

.ssh目录下创建操作机的公钥文件id_rsa.pub,将公钥内容拷贝进去

1
2
3
4
5
vim ~/.ssh/id_rsa.pub

//注意: 权限务必设置,否则连接不成功
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa.pub

目标机配置允许公私钥登录

1
2
# vim /etc/ssh/sshd_config 
# systemctl restart sshd
1
2
3
4
5
6
PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
#AuthorizedKeysFile .ssh/authorized_keys
AuthorizedKeysFile .ssh/id_rsa.pub

建立连接

1
2
chmod 400 ~/.ssh/id_rsa
ssh yezhou@192.168.0.2 -i ~/.ssh/id_rsa

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :