Skip to content

Instantly share code, notes, and snippets.

@mrtc0
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtc0/e41d4f2baced22c4c035 to your computer and use it in GitHub Desktop.
Save mrtc0/e41d4f2baced22c4c035 to your computer and use it in GitHub Desktop.
sshd_configのテンプレート
#####
# 2015.5.7
# sshd_configのテンプレート
# OpenSSH_6.8p1で動作確認
# rootユーザーのログインを拒否
# 公開鍵認証 + password認証の2段階認証
# さらに強固にしたいならGoogle認証システムを使った2段階認証にしたりする
# 転送機能をすべて禁止
# 暗号方式をAESに限定
# TCP Keep Aliveではなく, ClientAliveを使用
#
# 参考: OpenSSH実践入門 http://gihyo.jp/book/2014/978-4-7741-6807-4
#
Port 22 # 変更
AddressFamily any # IPv4とIPv6を使用. IPv4の場合はinet
Protocol 2 # バージョン2を使用
UsePrivilegeSeparation yes # 特権分離. ユーザ権限で処理.
Ciphers aes128-ctr,aes192-ctr,aes256-ctr # AESを使用
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
# ログ関係
SyslogFacility AUTHPRIV # AUTHではなくAUTHPRIVにしておく
LogLevel INFO # INFO, ERROR, FATALを出力.
# 認証周り
LoginGraceTime 30s # 認証処理のタイムアウト時間
PermitRootLogin no # rootでのログインを禁止
StrictModes yes # ログインユーザのファイル/ホームディレクトリのパーミッションなどをチェック
MaxAuthTries 3 # 最大認証試行回数を3回とする
MaxSessions 2 # 最大セッション数. 必要に応じて変更
## 必要に応じて設定
# AllowGroups
# Deny Groups
# AllowUsers
# DenyUsers
## chroot環境
## 内部ネットワーク外からのアクセスはchrootする
# ChrootDirectory /opt/chroot
# Match Address 192.168.0.0/24
# ChrootDirectory none
# 公開鍵認証
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
# ホストベースド認証
HostbasedAuthentication no
IgnoreRhosts yes
# パスワード認証
PasswordAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
# 公開鍵+パスワードの2段階認証
AuthenticationMethods publickey,password
# Kerberos options
KerberosAuthentication no
# GSSAPI options
GSSAPIAuthentication no
UsePAM no
# 転送周り
AllowAgentForwarding no # 認証エージェント転送の禁止
AllowTcpForwarding no # すべてのTCPフォワードを禁止
GatewayPorts no # ポートの中継を禁止
X11Forwarding no # X11転送を許可しない
PrintMotd yes # /etc/motdを表示するか
PrintLastLog yes # 前回のログイン日時を表示するか
TCPKeepAlive no # TCP keepaliveメッセージを送信しない. 一時的に経路が切れただけでもセッションが切断されるため.
PermitUserEnvironment no # .ssh/environmentかauthorized_keysを使用して環境変数を変更することを禁止
Compression delayed # ユーザーが認証後に圧縮
UseDNS no # 接続してきたクライアントのホスト名を逆引きしない
PermitTunnel no # 簡易VPNの禁止
ClientAliveInterval 60 # 60sごとにクライアントが生きているか確認する
ClientAliveCountMax 3 # 無反応のクライントに対してClient Allive Messageを送る回数. 指定した回数分連続で反応がない場合, セッションを切る.
# override default of no subsystems
Subsystem sftp /usr/lib/ssh/sftp-server
##### その他
#
# 脆弱な公開鍵リストの確認
# $ sudo apt-get install openssh-blacklist-extra
# $ ssh-vulnkey -v .ssh/authorizedkeys
# ブラックリストに載っていない場合は No blacklisted keys! と表示される.
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment