0.修改ssh配置文件
sudo vim /etc/ssh/sshd_config
|

修改以下内容
PremitRootLogin yes #启用允许Root用户登陆,修改为yes RSAAuthentication yes # 启用 RSA 认证,默认为yes PubkeyAuthentication yes # 启用公钥认证,默认为yes
|
1.生成ssh认证文件
ssh-keygen默认使用rsa算法,同时也可以使用较为详细的命令:
ssh-keygen -t ed25519 -b 1024 -f yourkeyname -C "备注"
|
参数 |
解释 |
-b |
采用长度1024bit的密钥对,b=bits,最长4096 |
-t |
采用rsa/dsa/ecdsa/ed25519 加密方式,t=type |
-f |
生成文件名,f=output_keyfiles |
-C |
备注,C=comment |
2.将产生的ssh公钥加入到服务器认证文件中
将公钥上传到服务器
方法一:
方法二:
scp id_rea.pub root@x.x.x.x:~/
|
将公钥加入到认证文件中
cat id_rsa.pub >> ~/.ssh/authorized_keys
|
重启ssh服务