本指南基于CentOS7平台操作
系统默认已安装openssh 7.4客户端与服务端
配置文件目录为/etc/ssh, 文件结构如下:
```powershell
moduli
ssh_config
sshd_config
ssh_host_ecdsa_key
ssh_host_ecdsa_key.pub
ssh_host_ed25519_key
ssh_host_ed25519_key.pub
ssh_host_rsa_key
ssh_host_rsa_key.pub
1.客户端配置
配置文件为ssh_config,
a: 生成密钥
命令:
```bash
ssh-keygen
将在用户目录生成.ssh目录,包含
id_rsa (私钥)
id_rsa.pub(公钥)
2个文件
b: 上传公钥到SSH服务器
命令:
ssh-copy-id root@110.112.118.88
输入服务器端用户密码,将会在SSH服务器的用户目录下,建立.ssh目录,上传公钥文件为authorized_keys
2.服务端配置
配置文件为sshd_config, 默认用户密码与密钥同时登录。密码登录存在中间人劫持风险,推荐基于密钥对的认证(免密码登录)。将配置文件中的PasswordAuthentication no 改为yes, 此时再用SSH密码认证登录会提示:Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
密钥文件名默认为id_rsa,如不同,连接时需加-i参数指定
ssh -i /xxx/rsa root@110.112.118.88