马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- #!/bin/bash# 设置公钥下载链接public_key_url="公钥网址"# 下载公钥文件wget -O /root/.ssh/id_rsa.pub "$public_key_url"# 检查 .ssh 文件夹是否存在,如果不存在则创建if [ ! -d "/root/.ssh" ]; then mkdir /root/.sshfi# 检查下载是否成功if [ $? -ne 0 ]; then echo "下载公钥文件失败,请检查公钥下载链接或网络连接。" exit 1fi# 备份 SSH 服务器配置文件cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak# 检测当前操作系统if [ -f /etc/redhat-release ]; then # CentOS 或 Red Hat 系列操作系统 # 禁用密码登录 sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config # 启用公钥登录 sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config # 设置公钥文件路径 sed -i 's/#AuthorizedKeysFile/AuthorizedKeysFile/' /etc/ssh/sshd_config echo "AuthorizedKeysFile .ssh/authorized_keys /root/.ssh/authorized_keys" >> /etc/ssh/sshd_config # 将公钥复制到 /root/.ssh/authorized_keys cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys # 设置正确的权限 chmod 700 /root/.ssh chmod 600 /root/.ssh/authorized_keys # 重启 SSH 服务 service sshd restartelif [ -f /etc/debian_version ]; then # Debian 或 Ubuntu 系列操作系统 # 禁用密码登录 sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config # 启用公钥登录 sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config # 设置公钥文件路径 sed -i 's/#AuthorizedKeysFile/AuthorizedKeysFile/' /etc/ssh/sshd_config echo "AuthorizedKeysFile .ssh/authorized_keys /root/.ssh/authorized_keys" >> /etc/ssh/sshd_config # 将公钥复制到 /root/.ssh/authorized_keys cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys # 设置正确的权限 chmod 700 /root/.ssh chmod 600 /root/.ssh/authorized_keys # 重启 SSH 服务 systemctl restart sshdelse echo "不支持的操作系统。" exit 1fi
复制代码
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站内容为站长个人技术研究记录或网络,不提供用户交互功能,所有内容版权归原作者所有。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|
|