生成SSH密钥对
CMD窗口输入以下命令生成SSH密钥对:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
按照提示选择保存路径和设置密码短语(也可以直接按回车键使用默认路径和不设置密码短语)
将公钥复制到远程Linux服务器
手动复制公钥内容
.ssh/id_rsa.pub
使用SSH连接到远程Linux服务器
ssh username@remote_host
将 username
替换为你的远程服务器用户名,将 remote_host
替换为远程服务器的IP地址或域名
在远程服务器上,编辑或创建 ~/.ssh/authorized_keys
文件:
mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys
将复制的公钥内容粘贴到 authorized_keys
文件中,然后保存并退出编辑器
确保 authorized_keys
文件的权限设置正确:
chmod 600 ~/.ssh/authorized_keys
确保 .ssh
目录的权限设置正确:
chmod 700 ~/.ssh
测试SSH免密登录
可以尝试通过SSH免密登录到远程Linux服务器:
ssh username@remote_host
如果一切顺利,应该能够直接登录到远程服务器而不需要输入密码。