建网站建网站的公司,门户网站的概念,大庆建设公司网站,百度网站地址提交一、生成SSH密钥对
在客户端主机 ClientHost上#xff0c;以 root用户身份生成SSH密钥对#xff1a;
ssh-keygen -t rsa -b 4096 -C your_emailexample.com
# -t rsa#xff1a;指定使用RSA算法
# -b 4096#xff1a;指定密钥长度为4096位
# -C …一、生成SSH密钥对
在客户端主机 ClientHost上以 root用户身份生成SSH密钥对
ssh-keygen -t rsa -b 4096 -C your_emailexample.com
# -t rsa指定使用RSA算法
# -b 4096指定密钥长度为4096位
# -C 添加注释用于标识密钥。 二、将公钥复制到服务端主机
使用 ssh-copy-id 命令将公钥复制到服务机 ServerHost 的 root 用户 ~/.ssh/authorized_keys 文件中
ssh-copy-id -i ~/.ssh/id_rsa.pub root192.168.29.28
# -i ~/.ssh/id_rsa.pub指定要复制的公钥文件。
# root192.168.29.28目标用户root和主机192.168.29.28。 三、确保服务端配置文件正确
在服务端主机 ServerHost 上确保SSH服务配置正确 检查并编辑 /etc/ssh/sshd_config 文件确保以下选项被正确设置。 # 允许公钥认证
PubkeyAuthentication yes# 禁止密码认证可选但推荐
PasswordAuthentication no# 确保ChallengeResponseAuthentication被禁用如果存在
ChallengeResponseAuthentication no# 允许使用.ssh/authorized_keys文件中的密钥
AuthorizedKeysFile .ssh/authorized_keys保存并关闭文件。 重启SSH服务以应用更改。 systemctl restart sshd
四、测试SSH免密登录 回到客户端主机 ClientHost尝试通过SSH连接到服务端主机 ServerHost不需要输入密码