「OpenSSH」- 通过密码登录

问题

针对安全性要求极低的场景,为了简化操作及管理,我们需要开启 SSH 密码登录;

该笔记将记录:OpenSSH 通过密码登录的方法,以及相关问题的解决办法;

方案

Server,允许 ROOT 登录

How to enable or disable password authentication in SSH

# --------------------------------------------------------- # 针对 Ubuntu 发行版

cat > /etc/ssh/sshd_config.d/root-with-pwd.conf <<EOF
PermitRootLogin yes
PasswordAuthentication yes
EOF

systemctl restart sshd.service

# --------------------------------------------------------- # 针对 CentOS 发行版

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
cat >> /etc/ssh/sshd_config <<EOF

PermitRootLogin yes
PasswordAuthentication yes
EOF

systemctl restart sshd.service

Client,强制使用密码登录

How to force ssh client to use only password auth? – Unix & Linux Stack Exchange

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no root@example.com

补充

在命令行中,使用 SSH 密码

Send the password through stdin in `ssh-copy-id`

sshpass -p "$TMP_PASS" ssh-copy-id