在本地生成ssh密钥,并查看
生成密钥
ssh-keygen -t ed25519 -C "your_email@example.com"
查看密钥 (进入ssh文件夹,查看文件名称,查看pub公钥内容)
cd ~/.ssh/
ls
id_rsa id_rsa.pub known_hosts
cat id_rsa.pub
此处会显示密钥内容,需要复制一下
使用密码登陆服务器,配置密钥
创建ssh
mkdir -p ~/.ssh
复制公钥内容到目标文件
echo "粘贴的公钥" >> ~/.ssh/authorized_keys
添加权限
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
服务器配置密钥登陆,关闭密码登陆
编辑ssh配置
vim /etc/ssh/sshd_config
查看PubkeyAuthentication、AuthorizedKeysFile、PasswordAuthentication修改配置项为后续配置内容
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
使用ssh连接测试
身份验证选择密钥
私钥地址填写本机的私钥地址 如
file:///Users/user/.ssh/id_rsa
测试链接