- 配置sshd服务 在服务器上修改/etc/ssh/sshd_config:
`<!-- lang: shell -->
1#禁止root登录 2PermitRootLogin no 3 4#指定可以登录的用户 5AllowUsers bob alice 6StrictModes yes 7 8#关闭密码验证 9PasswordAuthentication no 10 11#打开RSA验证相关设置 12RSAAuthentication yes 13PubkeyAuthentication yes 14 15AuthorizedKeysFile .ssh/authorized_keys 16 17#关闭 GSSAPI验证 18GSSAPIAuthentication no
`
重启sshd服务
- 生成rsa-keypair 切换到允许ssh登录的用户账户执行如下执行如下命令:
`<!-- lang: shell --> #生成key-pair ssh-keygen cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys sudo chmod 600 ~/.ssh/authorized_keys sudo chmod 700 ~/.ssh restorecon -R -v ~/.ssh
-
复制刚刚生成的id_rsa文件到本地,一般命名为:server.pem
-
ssh -i server.pem username@server