Linux 生成秘钥
ssh-keygen
windows powershell.sh
$HOST_IP="zhang@192.168.1.1"
$PUBPATH="$HOME\.ssh\id_rsa.pub"
$KEY=(Get-Content "$PUBPATH" | Out-String); ssh "$HOST_IP" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '${KEY}' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Linux配置免密登录
# 方法 1
ssh-copy-id -i ~/.ssh/id_rsa.pub zhang@192.168.1.1
# 方法 2(用于本机免密登录)
cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
Linux配置sudo免密
sudo vim /etc/sudoers
zhang ALL=(ALL:ALL) NOPASSWD:ALL