GCPのUbuntuでsshguardを有効にしてみる

GCP(Google Cloud Platform)で建ててみたサーバのsshへのアタックがかなり多いので(普通はsshのポート番号を変えておくのだと思いますが)sshguardとufwを連携してみます。

失敗したときシリアルコンソールで繋げられるように、パスワード付きのアカウントを一つ用意しておいて下さい(ユーザ名『ubuntu』のパスワードを変更でも良いかも)。

設定でちょっと嵌まったので、自分用にチラ裏。

# ufw自動起動設定
systemctl enable ufw
# ufw起動
ufw enable
# SSHを許可する例
ufw allow from 0.0.0.0/0 to any port ssh
# httpを許可する例
ufw allow from 0.0.0.0/0 to any port http
# GCPのヘルスチェッカーを許可
ufw allow from 169.254.169.254/32 to any
# ポリシー読み込み
ufw reload

# sshguardの設定(ちょっぴり厳しくしてみる)
vi /etc/default/sshguard
# 15行目
ARGS="-a 30 -p 420 -s 3600"
systemctl restart sshguard

念のため再起動して動作を確認して下さい。

# これらで確認してみる
tail -f /var/log/auth.log
systemctl status ufw
systemctl status sshguard
iptables -vL ufw-user-input
iptables -vL sshguard

設定に失敗してufwやsshguardがコケている時もありますので…。

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny