证书登陆的脚本.sh

#!/bin/bash

mkdir -p ~/.ssh  && cd ~/.ssh

# id_rsa.pub  authorized_keys   SSH 跳板机公钥
authorized_keys(){

cat <<EOF >>  authorized_keys

ssh-rsa 把你的公钥放这行 root  ##################################

EOF
}


no_use_passwd(){
    # 禁用密码登陆
    sed -i "s/PasswordAuthentication.*/PasswordAuthentication no/g"    /etc/ssh/sshd_config
    sed -i "s/#PasswordAuthentication.*/PasswordAuthentication no/g"   /etc/ssh/sshd_config

    # 只能SSH2访问,这个安全性高.
    sed -i '/Protocol/d' /etc/ssh/sshd_config
    echo "Protocol 2" >> /etc/ssh/sshd_config

    # 重启ssh服务
    systemctl restart ssh
}


##  启用功能

authorized_keys

no_use_passwd

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用 * 标注

© 2024 兰雅VBA代码分享
浙ICP备2021017795号-2 浙公网安备33078102100266号