ããã«ã¡ã¯ãäºæ¥æ¨é²é¨ã®å»£ç°ã§ãã
NFLabs. ã¢ããã³ãã«ã¬ã³ãã¼3æ¥ç®ã¨ãããã¨ã§ã
æ¬ç¨¿ã§ã¯sshæ¥ç¶æã®äºè¦ç´ èªè¨¼ã®å®è£
ã«ã¤ãã¦æ¸ãã¦ã¿ããã¨æãã¾ãã
ã¯ããã«
ç¾å¨ç§ã¯NTTã³ãã¥ãã±ã¼ã·ã§ã³ãºæ ªå¼ä¼ç¤¾ããNFLabs.ã«åºåãã¦ããã®ã§ãããåºåãã¦ããåã«NFLabs.ãå®æ½ããã»ãã¥ãªãã£ã¨ã³ã¸ãã¢è²æç ä¿®ã«ãªãã¥ã©ã ãé·æéã¿ã£ã¡ããã£ã¦ãã¨åè¬ãã¦ãã¾ããã
ç ä¿®ã§ã¯ãµã¼ãæ§ç¯ãªã©åºæ¬çãªå
容ããã½ããã¦ã§ã¢éçºããããã¬ã¼ã·ã§ã³çãã»ãã¥ãªãã£ã¨ã³ã¸ãã¢ã«å¿
é ã¨ãªãã¹ãã«ãä½ç³»çã«å¹
åºãå¦ã¶ãã¨ãã§ããä»åã¯ãµã¼ãæ§ç¯ã®æã«åãçµãã 課é¡ã«ã¤ãã¦ã®ã話ã§ãã
ã©ããªèª²é¡ã ã£ãã®ï¼
ç 修課é¡ã®ä¸ã§sshéµèªè¨¼ãå®è£ ããWebãµã¼ããæ§ç¯ããã®ã§ãããããã§è¿½å 課é¡ã¨ãã¦æ¬¡ã®ãããªãé¡ãããã ãã¾ããã
- æ§ç¯ããWebãµã¼ããããã«ã»ãã¥ã¢ã«è¨å®ãããã¨
- èå¼±ãªè¨å®ãããã°ãã®ä¿®æ£ãããã使ç¨ãã¦ããããã«ã¦ã§ã¢ã«ããã«ã»ãã¥ã¢ãªè¨å®ãããããã
- ä¸è¨ãæºããããã«èªç±ã«åãçµãã§OK
ã¨ã¾ãããããªæãã ã£ãã®ã§ãä½ããããããªã¼ã¨ã¤ã³ã¿ã¼ãããã彷徨ã£ã¦ããããã§ããã
åºä¼ãã¯çªç¶ã«
ãã¼ãâ¦ã©ããããã®ãããã ã¨ããããçºãã¦ããã¨ããããµã¨ãããã¨ããGoogle Authenticatorã使ã£ã¦äºè¦ç´ èªè¨¼ãå°å
¥ã§ãããã¨ãç¥ãããã®å°å
¥éç¨ã§terminalç»é¢ã«ããã¡ã³ï¼ã¨ï¼±ï¼²ã³ã¼ããã§ãã§ãã¨è¡¨ç¤ºããããã¨ã«è¡æãåãããã è¡æãåããããã¨ããçç±ã§sshæ¥ç¶æã®äºè¦ç´ èªè¨¼ã®å®è£
ããã¼ãã«ãããã¨æ±ºããã®ã§ããã
課é¡è¨å®
ãã¼ãã決ã¾ã£ããã¨ãªã®ã§ãåå¼·ãã¦ãæ¶ç©ºã®è¦ä»¶ãç¡é§ã«çµ¡ãã¤ã¤èªèº«ã®åãçµã¿å 容ã次ã®ããã«è¨å®ãã¦ã¿ã¾ãããã´ã¼ã«ãæ確ã«ããã®ã¯å¤§äºã§ããããã
å®æ½å 容
Google Authenticatorã使ã£ãsshæ¥ç¶æã®äºè¦ç´ èªè¨¼ã®å®è£
å®æ½ç®ç
æ§ç¯ãããµã¼ãã§ã¯éµèªè¨¼ã¾ã§ãå®è£ ãã¦ããããããã«éµãã¡ã¤ã«ã®æµåºãªã¹ã¯ãå å³ããGoogle Authenticatorã«ããã¯ã³ã¿ã¤ã ãã¹ã¯ã¼ãèªè¨¼ã追å ããäºè¦ç´ èªè¨¼ã®å®è£ ã«ãããããã»ãã¥ã¢ãªãµã¼ãã¨ããã
å®è£ è¦ä»¶
éµèªè¨¼ï¼Google Authenticatorã®äºè¦ç´ èªè¨¼ãåºæ¬è¨å®ã¨ããã
â»ãã¹ã¯ã¼ãèªè¨¼ã¯çç¥ãä¸æ®µéèªè¨¼ã«ã¯ããªããç¹å®ã®ã¦ã¼ã¶ã¯ãã¹ã¯ã¼ãèªè¨¼ã®ã¿ã§OKã¨ããã
â»ã·ã¹ãã ã¨ãç¹å®ã®ã¢ã«ã¦ã³ãã ãã¯ãã¹ã¯ã¼ãèªè¨¼ã«ãããã¿ãããªè¦ä»¶ãããæ³å®ã§â¦èªè¨¼ã®é çªã¯éµèªè¨¼ -> Google Authenticatorã¨ããã
å®è£ æé
ããã§ã¯æ§ç¯ãã¦ããã¾ãããã
æ§ç¯ç°å¢
åææ¡ä»¶
- sshéµèªè¨¼ãå®è£
ãããsshãµã¼ãããã§ã«æ§ç¯ãã¦ãããã®ã¨ããã
â»æ§ç¯æ¹æ³ã¯ã°ã°ãã°ããããã®å 人ãã¡ãæãã¦ããã¾ãã
æé (1). Google Authenticatorã®ã¤ã³ã¹ãã¼ã«
Google Authenticatorã¢ããªãæå ã®ã¹ãã¼ããã©ã³ã«ã¤ã³ã¹ãã¼ã«ãã¾ãã
â»ç§ã¯ã¹ãã¼ããã©ã³ã«Google Authenticatorãã¤ã³ã¹ãã¼ã«ãã¦TOTPï¼ã¿ã¤ã ãã¼ã¹ã»ã¯ã³ã¿ã¤ã ãã¹ã¯ã¼ãï¼ãçæããããã«ãã¾ãããã TOTPããçæã§ããã°Microsoft Authenticatorã¢ããªãã¹ãã¼ããã©ã³ã«ã¤ã³ã¹ãã¼ã«ããã§ãã WinAuthãPCã«ã¤ã³ã¹ãã¼ã«ããã§ãä½ã§ãããã§ããç¶ãã¦EPELãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ sudo yum install epel-release
- Google Authenticatore PAMã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ sudo yum install google-authenticator
æé (2). Google Authenticatorã®è¨å®
- Google Authenticatorãè¨å®ããã¦ã¼ã¶ã§ä¸è¨ã³ãã³ããå®è¡ããã¨å¯¾è©±å½¢å¼ã§Google Authenticatorã®è¨å®ãéå§ãã¾ããè¨å®ã®ããã«é çªã«è³ªåããã¾ãããåºæ¬çã«ãã¹ã¦ãyãã§å¤§ä¸å¤«ã§ãã
$ google-authenticator
- y ã®å ´åã¯æéãã¼ã¹ã®ç¢ºèªã³ã¼ããçæãããn ã®å ´åã¯ã«ã¦ã³ã¿ã¼ãã¼ã¹ã®ç¢ºèªã³ã¼ããçæããã¾ããä»åã¯æéãã¼ã¹ãé¸æãã¾ãã
Do you want authentication tokens to be time-based (y/n) y
- ä¸ã®ãããªQRã³ã¼ããã§ã£ãã表示ãããã®ã§ãã¹ãã¼ããã©ã³ã«ã¤ã³ã¹ãã¼ã«ããGoogle Authenticatorã¢ããªã§QRã³ã¼ããã¹ãã£ã³ãã¦ç»é²ãã¾ãã Microsoft Authenticatorã¢ããªã®å ´åãåæ§ã«QRã³ã¼ããã¹ãã£ã³ãã¦ç»é²ãã¾ããï¼QRã³ã¼ãã表示ãããªãå ´åã¯ã表示ãããURLã«ã¢ã¯ã»ã¹ããã°QRã³ã¼ãã表示ã§ããï¼
- QRã³ã¼ãã®ä¸ã«Google Authenticatorã¢ããªã使ããªããªã£ãæã®ããã®ç·æ¥ã³ã¼ãã表示ããã¾ããä½ããã£ãæã®ããã«æå ã«æ§ãã¦ããã¾ãããã
WinAuthã§TOTPãçæãããéã«ã¯ããã®1ã®é¨åã«QRã³ã¼ãã¨ä¸ç·ã«çæãããSecret Codeãå ¥åãã¦ãã ããã
Google Authenticator ã®ç§å¯éµãè¨å®æ å ±ã表示ããã¦ãããã¹ã«ä¿åãã¦ããããã®ç¢ºèªã§ããå¤æ´ã®å¿ è¦ããªããã°ãã®ã¾ã¾yã§é²ãã¾ãããã
Do you want me to update your "/home/test/.google_authenticator" file? (y/n) y
- åã確èªã³ã¼ããè¤æ°å使ããã¨ãç¦æ¢ããè¨å®ã§ããyã«ããã¨30ç§ãã¨ã«ï¼åã®ãã°ã¤ã³ã«å¶éããã¾ãã
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
- ã¯ã©ã¤ã¢ã³ãï¼Google Authenticatorãã¤ã³ã¹ãã¼ã«ããã¹ãã¼ããã©ã³ï¼ã¨ãµã¼ãã§æ大ï¼åã®æéã®ããã許容ããè¨å®ã§ããã¹ãã¼ããã©ã³ã®æéãããããã¨ã¯ç¨ã«ããã®ã§ y ã«ãã¦ããã®ãããã¨æãã¾ããã
By default, a new token is generated every 30 seconds by the mobile app. 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. This allows for a time skew of up to 30 seconds between authentication server and client. If you experience problems with poor time synchronization, you can increase the window from its default size of 3 permitted codes (one previous code, the current code, the next code) to 17 permitted codes (the 8 previous codes, the current code, and the 8 next codes). This will permit for a time skew of up to 4 minutes between client and server. Do you want to do so? (y/n) y
- 30ç§ãã¨ã«3åã¾ã§ã®ãã°ã¤ã³è©¦è¡ã«å¶éããè¨å®ã§ããã¤ã¾ã確èªã³ã¼ãã3åééããã¨ãã®ç¢ºèªã³ã¼ãã¯ç¡å¹ã«ãªãã¾ããy ã«ããå ´åã¯ãããã㦠Google Authenticator PAMã¢ã¸ã¥ã¼ã«ã® echo_verification_code ãªãã·ã§ã³ãä»ãã¦ããã®ãããã§ãã
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
æé (3). ãã£ã¬ã³ã¸ã¢ã³ãã¬ã¹ãã³ã¹èªè¨¼ã¨äºè¦ç´ èªè¨¼ã®æå¹å
- ãã£ã¬ã³ã¸ã¢ã³ãã¬ã¹ãã³ã¹èªè¨¼ãæå¹åãããããsshd_configã®ä¿®æ£ããã¾ãã
$ sudo vi /etc/ssh/sshd_config
ChallengeResponseAuthentication no â ChallengeResponseAuthentication yes
- äºè¦ç´ èªè¨¼ãæå¹ã¨ãªãããsshd_configã®æçµè¡ã«æ¬¡ã®1è¡ã追å ãã¾ãã
AuthenticationMethods publickey,keyboard-interactive
- sshdãåèµ·åãã¾ãã
$ sudo systemctl restart sshd
æé (4). NTPãµã¼ãã®æå»åæç¶æ ã®ç¢ºèª
ãµã¼ãã®æéãæå»åæããã¦ããªãã¨Google Authenticatoreã®èªè¨¼ãã¹ãã¼ããã©ã³ã®æéã¨ããããã失æãã¦ãã¾ãã¾ãã
- æå»åæç¶æ ã確èªãã¾ãã
$ timedatectl
NTP synchronized: yesã¨ãªã£ã¦ãããã¨ã確èªãã¾ãã
- NTP synchronized: noã¨ãªã£ã¦ããå ´åã¯chronydãåèµ·åãã¾ãã
- å°ãæéãçµã¤ã¨yesã«ãªãã¯ãã
$ sudo systemctl restart chronyd $ timedatectl
chronydãåèµ·åå¾NTP synchronized: yesã¨ãªã£ã¦ãããã¨ã確èªãã¾ãã
æé (5). sshdã®PAMã¢ã¸ã¥ã¼ã«ã¸ã®Google Authenticatorã®PAMã¢ã¸ã¥ã¼ã«ã®çµã¿è¾¼ã¿
- SSHèªè¨¼ã®éã«Google Authenticatorã®PAMã¢ã¸ã¥ã¼ã«ãå¼ã³åºãããããã«sshdã®PAMã¢ã¸ã¥ã¼ã«ã®ãã¡ã¤ã«ã®æå¾ã«ä»¥ä¸ã®è¡ã追è¨ãã¾ãã
$ sudo vi /etc/pam.d/sshd
auth required pam_google_authenticator.so nullok echo_verification_code
ããã¾ã§ã®è¨å®ã«ãããSSHãã°ã¤ã³ã®éã«éµèªè¨¼ã«å ãã¦ãGoogle Authenticatorã®ç¢ºèªã³ã¼ãï¼keyboard-interactiveï¼ã®èªè¨¼ãæ±ããããããã«ãªãã¾ãããã ããkeyboard-interactiveã«ã¯ãã¹ã¯ã¼ãèªè¨¼ãå«ã¾ãããããéµèªè¨¼âãã¹ã¯ã¼ãèªè¨¼â確èªã³ã¼ãã®3段éèªè¨¼ã¨ãªã£ã¦ãã¾ãã
ï¼è£è¶³ï¼PAMã¢ã¸ã¥ã¼ã«ãªãã·ã§ã³ã«ã¤ãã¦
nullok
Google Authenticator ãè¨å®ãã¦ããªãã¦ã¼ã¶ã¼ããèªè¨¼ã³ã¼ããªãã§ãã°ã¤ã³ã§ãããã¨ã許å¯ãã¾ãããã®ãªãã·ã§ã³ãè¨å®ããã¦ããªãã¨Google Authenticatorãå°å
¥ãã¦ããªãã¦ã¼ã¶ã®èªè¨¼ã失æãã¦ãã¾ããããç¹å®ã¦ã¼ã¶ã®ããã«ãã®ãªãã·ã§ã³ãå¿
è¦ã§ãã
echo_verification_code
å
¥åæã«èªè¨¼ã³ã¼ãã表示ãã¾ãã確å®ã«èªè¨¼ã³ã¼ããå
¥åã§ããããã«ä»ãã¦ããã®ãããã§ããèªè¨¼ã³ã¼ãã®æå¹æéã¯30ç§ãªã®ã§è¡¨ç¤ºãã¦ãç¹ã«åé¡ã¯ãªãã¨æãã¾ãã
æé (6). ç¹å®ã¦ã¼ã¶ã®ä¾å¤å¦çã®å®è£ ã¨ãã¹ã¯ã¼ãèªè¨¼ã®åæ¢
- ç¹å®ã¦ã¼ã¶ã¯ãã¹ã¯ã¼ãèªè¨¼ã®ã¿ã¨ãªãããã«sshd_configã«ä»¥ä¸ã®è¡ã追è¨ãã¾ããï¼ç¹å®ã¦ã¼ã¶ãaaaaãbbbbã¨åå¨ããå ´åã®ä¾ï¼
$ sudo vi /etc/ssh/sshd_config
AuthenticationMethods publickey,keyboard-interactive â AuthenticationMethods publickey,keyboard-interactive Match User aaaa AuthenticationMethods keyboard-interactive Match User bbbb AuthenticationMethods keyboard-interactive
ç¹å®ã¦ã¼ã¶ãè¤æ°ããå ´åã¯Match User xxxxãAuthenticationMethodsã»ã»ã»ã®2è¡ã追å ãã¦ããã¾ãã
- sshdãåèµ·åãã¾ãã
$ sudo systemctl restart sshd
- ç¹å®ã¦ã¼ã¶ä»¥å¤ã¯ãã¹ã¯ã¼ãèªè¨¼ãå®æ½ããªãããpassword-authã®PAMã¢ã¸ã¥ã¼ã«ã«ä»¥ä¸ã®è¡ã追è¨ãã¾ããï¼ç¹å®ã¦ã¼ã¶ãaaaaãbbbbã¨åå¨ããå ´åã®ä¾ï¼
$ sudo vi /etc/pam.d/password-auth
auth required pam_faildelay.so delay=2000000 auth sufficient pam_unix.so nullok try_first_pass â auth required pam_faildelay.so delay=2000000 auth sufficient pam_succeed_if.so login notin aaaa:bbbb auth sufficient pam_unix.so nullok try_first_pass
ãã®è¨å®ã«ããç¹å®ã¦ã¼ã¶ã«ä¸è´ããªãå ´åã¯ããã¹ã¯ã¼ãèªè¨¼ãèµ°ãåã«password-authã®PAMãæãããã¨ãã§ãã¾ããç¹å®ã¦ã¼ã¶ãããã«åå¨ããå ´åã¯aaaa:bbbb:cccc:ã»ã»ã»ã¨è¿½å ãã¦ããããç¹å®ã¦ã¼ã¶ç¨ã®ã¦ã¼ã¶ã°ã«ã¼ããç¨æãã¦ä¾å¤å¦çãå®æ½ãã¾ãã
ï¼ãã¾ãï¼ teratermã§äºè¦ç´ èªè¨¼æ¥ç¶ãå©ç¨ãããã¨ã
teratermãé常使ç¨ããå ´åãäºè¦ç´ èªè¨¼æ¥ç¶ãã§ããªãä»æ§ããããã¡ãã£ã¨ãã工夫ãå¿ è¦ã¨ãªãã¾ãã
解決æ¹æ³ãã®ï¼
- puttyã®å°å ¥
ãããè¨ã£ã¦ãã¾ãã¨å ãåããªãã®ã§ãããå®éputtyã§ããã°æ®éã«äºè¦ç´ èªè¨¼ã対å¿ã§ãã¾ãããã¨ãªããteratermã®å©ç¨ã諦ããã®ãä¸ã¤ã®æã§ãã
解決æ¹æ³ãã®ï¼
- äºè¦ç´ èªè¨¼ç¨ã®teratermèµ·åbatãã¡ã¤ã«ã®ä½æ
以ä¸ã®ãããªbatãã¡ã¤ã«ãä½æãã¾ãã
"C:\Program Files (x86)\teraterm\ttermpro.exe" <æ¥ç¶å ãµã¼ãã®IPã¢ãã¬ã¹>:<SSHã®ãã¼ãçªå·> /ssh2 /auth=publickey /ask4passwd /keyfile="<ç§å¯éµãã¡ã¤ã«ã®ãã¹>"
ä½æããbatãã¡ã¤ã«ãèµ·åããã¨teratermãç«ã¡ä¸ããã®ã§ãã¦ã¼ã¶åã¨ãã¹ãã¬ã¼ãºãå
¥åããã¾ãéµèªè¨¼ã§ã®æ¥ç¶ã試ã¿ã¾ãã
ãèªè¨¼ã«å¤±æãã¾ãããå試è¡ãã¦ãã ãããã¨è¿ãããããæ°ã«ããèªè¨¼æ¹å¼ãããã¼ãã¼ãã¤ã³ã¿ã©ã¯ãã£ãèªè¨¼ã使ããã«è¨å®ãæ¥ç¶ããã¨äºè¦ç´ èªè¨¼ã®èªè¨¼ã³ã¼ããæ±ããããã®ã§ãæ£ããã³ã¼ããå
¥åããã¨ãã°ã¤ã³ã§ãã¾ãã
ï¼ãã¾ã2ï¼ authy-sshã使ã£ãäºè¦ç´ èªè¨¼
ããã¾ã§Google Authenticatorã®PAMã¢ã¸ã¥ã¼ã«ã使ã£ãäºè¦ç´ èªè¨¼ã®è©±ããã¦ãã¾ãããã
ä»ã«ãäºè¦ç´ èªè¨¼ãå®ç¾ããæ¹æ³ã¯ãããä¸ä¾ã¨ãã¦authy-sshã使ã£ã¦äºè¦ç´ èªè¨¼ãã§ãã¾ãã
å°å
¥æ¹æ³ã®è©³ç´°ã¯å²æãã¾ãããå
¬å¼ãµã¤ããgithubã
åèã«ãã¦ãé å¼µã£ã¦APIãã¼ãã¨ã£ã¦ãããããªããsshãµã¼ãå´ã«authy-sshãå°å
¥ããã°ã
å
ã»ã©ã¾ã§ã¨ã¯ã¾ãéã£ãå½¢ã§äºè¦ç´ èªè¨¼ãå°å
¥ãããã¨ãã§ãã¾ãã
ã©ããªæãã«åãã®ãã¯å
¬å¼ãµã¤ãã®åç»ãè¦ã¦ããã ãã¨ã¤ã¡ã¼ã¸ãã¤ãã¨æãã¾ãããè¨å®ããç¹å®ã®ã¦ã¼ã¶ã«sshæ¥ç¶ãããã¨ããã¨
authy-sshã®èªè¨¼ãã©ã°ã¤ã³ãéã«å
¥ã£ã¦ãã¦äºè¦ç´ èªè¨¼ãå®ç¾ãããã¨ãã§ãã¾ãã
以ä¸ã®æé ã§è¨å®ããè¦ä»¶ãæºããsshæ¥ç¶æã®äºè¦ç´ èªè¨¼ã®å®è£
ãå®ç¾ãããã¨ãã§ãã¾ããã
ç¹å®ã¦ã¼ã¶ã®å¶å¾¡ã®å®è£
ã«ã¤ãã¦ã¯ã対象ã®ç¹å®ã¦ã¼ã¶ã大éã«åºã¦ãããããªç°å¢ã ã¨éç¨ãããã©ããæ¬å½ã¯ããå°ãè³¢ãããæ¹ãããã®ããããã¾ããã
ã¾ã¨ã
sshæ¥ç¶æã®äºè¦ç´ èªè¨¼ãå®è£ ããã»ãã¥ã¢ãªãµã¼ããæ§ç¯ã§ãã
åç´ãªå®è£ ã§ã¯ãªãããããããããªãéç¨è¦ä»¶ãæ³åãããã®è¦ä»¶ãåãå ¥ãã¦å®è£ ãå®ç¾ãã
æ¬ç¨¿ãè¨è¼ããã«ãããåèã«ããã¦ããã ããURL
https://blog.apar.jp/linux/12502/
http://naoberry.com/tech/two-step-authentication/
https://www.bigbang.mydns.jp/ssh-ga-x.htm
http://www.linux-pam.org/Linux-PAM-html/sag-pam_succeed_if.html
http://blog.techfirm.co.jp/2018/05/23/
https://www.authy.com/integrations/ssh/