Mastodon
  • 什么是Mastodon?
  • 使用Mastodon
    • 创建一个帐户
    • 设置个人资料
    • 发布嘟文
    • 使用社交功能
    • 处理不想要的内容
    • 推广自己和他人
    • 设置你的首选项
    • 更多设置
    • 站外使用Mastodon
    • 迁移或删除帐户
    • 运行自己的服务器
  • 运营Mastodon
    • 准备你的机器
    • 从源中安装
    • 设置你的环境
    • 安装可选特色功能
      • 全文搜索
      • 匿名服务
      • 单点登录(SSO)
    • 配置你的新实例
    • 使用管理命令行
    • 升级到新版本
    • 备份你的服务器
    • 迁移到新机器
    • 伸缩你的服务器
    • 运营操作
    • 故障分析
  • 开发Mastodon应用
  • 向Mastodon项目做贡献
  • 遵循的标准
  • REST API
  • API 方法
  • API 实体

准备你的机器

    • 禁止密码登录SSH(仅允许密钥登录)
    • 更新系统
    • 安装 fail2ban 以阻止重复登录尝试
    • 安装防火墙并只暴露SSH、HTTP、HTTPS端口

如果你正在设置一台全新的机器,推荐你首要完成安全设置。以下内容假定你运行 Ubuntu 18.04:

禁止密码登录SSH(仅允许密钥登录)

首先,请确保你实际上是通过密钥而不是通过密码登录到服务器的,否则这将使你无法登录。许多托管服务提供商支持上传公钥,并自动为新机器设置基于密钥的root登录。

编辑 /etc/ssh/sshd_config 并找到 PasswordAuthentication。确保它已被去除注释并被设为 no。如果你做了任何改动,请重启 sshd。

更新系统

apt update && apt upgrade -y

安装 fail2ban 以阻止重复登录尝试

编辑 /etc/fail2ban/jail.local 并添加以下内容:

[DEFAULT]
destemail = your@email.here
sendername = Fail2Ban

[sshd]
enabled = true
port = 22

[sshd-ddos]
enabled = true
port = 22

最后重启fail2ban:

systemctl restart fail2ban

安装防火墙并只暴露SSH、HTTP、HTTPS端口

首先,安装 iptables-persistent。在安装期间,它将询问你是否保留现有规则。

apt install -y iptables-persistent

编辑 /etc/iptables/rules.v4 并添加如下内容:

*filter

#  Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT

#  Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#  Allow all outbound traffic - you can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT

#  Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

#  Allow SSH connections
#  The -dport number should be the same port number you set in sshd_config
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

#  Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

#  Log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

#  Reject all other inbound - default deny unless explicitly allowed policy
-A INPUT -j REJECT
-A FORWARD -j REJECT

COMMIT

iptables-persistent 将在机器启动时自动加载配置。但是由于我们现在不会立刻重启,我们需要第一次手动加载它:

iptables-restore < /etc/iptables/rules.v4

翻译状态: 本文是英文页面 Preparing your machine 的翻译,最后翻译时间:,点击这里可以查看翻译后页面的改动。

最后更新于 May 21, 2020 · 改进此页面
也可在此找到: English

Sponsored by

Dotcom-Monitor LoadView Stephen Tures Swayable SponsorMotion

加入Mastodon · 博客 · ·

查看源代码 · CC BY-SA 4.0 · 版权信息