Neste post vou mostrar para você como instalar e configurar o Google Authenticator junto com o SSH.
Para começar instale o libpam-google-authenticator.
[krix@rogue]$ sudo apt-get install libpam-google-authenticator |
Em seguida execute o google-authenticator para gerar a chave secreta e adicionar o arquivo no home do usuário.
[krix@rogue]$ google-authenticator https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/krix@sorceress%3Fsecret%3DKKKKKKKKKKKKKKKK Your new secret key is: KKKKKKKKKKKKKKKK Your verification code is 065211 Your emergency scratch codes are: 42231304 79413861 58506139 15737255 89850700 Do you want me to update your "~/.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 |
Use o aplicativo do Google Authenticator para ler o QRCode gerado ou adicione manualmente:

Para ativar esta autenticação no ssh você precisa alterar o arquivo /etc/pam.d/sshd.
[krix@rogue]$ sudo vi /etc/pam.d/sshd auth required pam_google_authenticator.so |
No arquivo de configuração do ssh adicione a linha abaixo:
[krix@rogue]$ sudo vi /etc/ssh/sshd_config ChallengeResponseAuthentication yes |
Reinicie o SSH para que as alterações sejam carregadas.
[krix@rogue]$ sudo service ssh restart |
Agora é só testar
[krix@rogue]$ ssh localhost Verification code: Password: |
Você pode fazer isso não somente para o SSH, mas para o login. Basta adicionar a linha abaixo no arquivo de configuração do lightdm ou do gdm:
auth required pam_google_authenticator.so |