Linux配置公钥授权方式ssh连接
本地机
生成Key
ssh-keygen -t rsa
//passphrase务必为空
在~/.ssh
目录下生成私钥id_rsa
和公钥id_rsa.pub
将公钥上传或复制到目标机 .ssh 目录下
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDun/aN5lomQhxFn2dYfTOhMnemPJaeaAlaZv9Do2t5vH2KRr7PHv89swkjMC/HvD0oK+iJ66cAypotqnlizdJv487SWOfQplEa5e6PeIpXDvjeqiuyyb25vbX3Io7IeEli1DupZPjXjmahVf70etKUl5v2GettM3OOKewO4v+q4WabBvyfyrvwrqboX1fbO5j/X6gAPy7csu0tyrnEGG5D2R/KkrqIts1lpQ3fx3+wGqidfWDyGqa2e+XQ4l3E60534lB7pq8aACsJrgR5c500Uca9b53dpz8WWwXvfQuda2FFBR5SQ6jVu7jGupHQqOHZb3I/+I91ol4nxmJaDbJp yezhou@appblog-gateway
远程机
在.ssh
目录下创建操作机的公钥文件id_rsa.pub
,将公钥内容拷贝进去
vim ~/.ssh/id_rsa.pub
//注意: 权限务必设置,否则连接不成功
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa.pub
目标机配置允许公私钥登录
# vim /etc/ssh/sshd_config
# systemctl restart sshd
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
建立连接
chmod 400 ~/.ssh/id_rsa
ssh yezhou@192.168.0.2 -i ~/.ssh/id_rsa
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/26/linux-config-public-key-authorization-method-ssh-connection/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Linux配置公钥授权方式ssh连接
本地机
生成Key
ssh-keygen -t rsa
//passphrase务必为空
在~/.ssh目录下生成私钥id_rsa和公钥id_rsa.pub
将公钥上传或复制到目标机 .ssh 目录下
ssh-rsa AAA……
文章目录
关闭
共有 0 条评论