设置 ssh 无密码登录
- 检查现有 SSH 密钥对。
> ls -al ~/.ssh/id_*.pub
> No such file or directory
- 生成新的 SSH 密钥对。
> ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
> Enter file in which to save the key (/home/yourusername/.ssh/id_rsa):
> Enter passphrase (empty for no passphrase):
ls ~/.ssh/id_*/home/yourusername/.ssh/id_rsa /home/yourusername/.ssh/id_rsa.pub
- 复制公钥。
> ssh-copy-id rumenz@rumenz.com
> rumenz@rumenz.com's password:
> cat ~/.ssh/id_rsa.pub | ssh rumenz@rumenz.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
- 使用 SSH 密钥登录到你的服务器。
> ssh rumenz@rumenz.com
禁用 SSH 密码认证
- 以具有 sudo 权限或 root 的用户身份使用 SSH 密钥登录远程服务器:
> ssh sudo_user@server_ip_address
- 打开 SSH 配置文件 /etc/ssh/sshd_config,搜索如下指令,修改如下:
> vim /etc/ssh/sshd_config PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no
> systemctl restart ssh
> systemctl restart sshd
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END