SSHを保護および保護するためにできることがいくつかあります。それらの1つは、Google Authenticatorを使用して、CentOSVPSで2要素認証を作成することです。 Google Authenticatorは、SSH経由でサーバーにログインするためにユーザー名とパスワードとともに入力する必要があるタイムベースのワンタイムパスワード(TOTP)をスマートフォンで生成することにより、セキュリティをさらに強化します。
今日のブログ記事では、ソースからGoogle認証システムをインストールし、2要素認証用にSSHを構成する方法について説明します。
まず、CentOS仮想サーバーを更新します
yum -y update
次に、「 pam-devel」をインストールします ‘認証を処理するプログラムを再コンパイルせずに認証ポリシーを設定できるパッケージ。
yum -y install pam-devel
TOTPセキュリティトークンは時間に敏感であるため、ntpdがインストールされ実行されていることを確認してください
yum -y install ntp /etc/init.d/ntpd start chkconfig ntpd on
Google認証システムパッケージをダウンロードして解凍します
cd /opt/ wget https://google-authenticator.googlecode.com/files/libpam-google-authenticator-1.0-source.tar.bz2 tar -xvzf libpam-google-authenticator-1.0-source.tar.bz2 cd libpam-google-authenticator-1.0
Google認証システムモジュールをコンパイルしてインストールします
make make install
次に、サーバーでGoogle認証システムを実行し、各質問に答えます
google-authenticator Do you want authentication tokens to be time-based (y/n) y https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@YOURHOSTNAME%3Fsecret%3DWYD4YCGEE5N4M3LA Your new secret key is: WYD4YCGEE5N4M3LA Your verification code is 188127 Your emergency scratch codes are: 60086389 28918071 88502143 60873576 90892542 Do you want me to update your "/root/.google_authenticator" file (y/n) y Do you want to disallow multiple uses of the same authentication token? This restricts you to one login about every 30s, but it increases your chances to notice or even prevent man-in-the-middle attacks (y/n) y By default, tokens are good for 30 seconds and in order to compensate for possible time-skew between the client and the server, we allow an extra token before and after the current time. If you experience problems with poor time synchronization, you can increase the window from its default size of 1:30min to about 4min. Do you want to do so (y/n) y If the computer that you are logging into isn't hardened against brute-force login attempts, you can enable rate-limiting for the authentication module. By default, this limits attackers to no more than 3 login attempts every 30s. Do you want to enable rate-limiting (y/n) y
最初の質問に答えた後に指定されたURLを開き、スマートフォンのGoogle認証システムアプリケーションを使用してQRコードをスキャンします。それで全部です。新しい確認コードは30秒ごとに生成されます。
次に、SSHログインに対してGoogle認証システムを有効にする必要があります。 PAMの構成ファイルを開きます
vi /etc/pam.d/sshd
そして、上部に次の行を追加します
auth required pam_google_authenticator.so
SSH構成ファイルを開き、「 ChallengeResponseAuthentication ‘行はyesに設定されています
ChallengeResponseAuthentication yes
変更を保存してSSHサービスを再起動します:
service sshd restart
これで、サーバーにSSHで接続しようとするたびに、Google認証システムアプリケーションに表示される確認コードを入力するよう求められます。
login as: Verification code: Password:
もちろん、Linux VPS Hostingをご利用の場合は、これを行う必要はありません。管理者に質問し、座ってリラックスしてください。管理者がすぐにこれを設定します。アップデートについては、Ubuntu16.04で2要素認証を使用したSecureSSHを参照できます。
PS。 この投稿が気に入った場合は、左側のボタンを使用してソーシャルネットワーク上の友達と共有するか、下に返信を残してください。ありがとう。