I'm trying to secure an outbound server with Google 2FA solution.
For the time being, I'm first configuring everything on a local Vagrant machine and once everything works as intended I'll run it as an Ansible playbook on the remote outbound machine.
I've configured /etc/ssh/sshd_config
like so:
Port 22
Protocol 2
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
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication yes
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
Match User rescue
AuthenticationMethods publickey
Match Group gauth
AuthenticationMethods publickey,keyboard-interactive
and /etc/pam.d/sshd
like so:
auth required pam_google_authenticator.so nullok
account required pam_nologin.so
@include common-account
session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close
session required pam_loginuid.so
session optional pam_keyinit.so force revoke
@include common-session
session optional pam_motd.so motd=/run/motd.dynamic noupdate
session optional pam_motd.so # [1]
session optional pam_mail.so standard noenv # [1]
session required pam_limits.so
session required pam_env.so # [1]
session required pam_env.so user_readenv=1 envfile=/etc/default/locale
session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open
@include common-password
For some reason, users which are not members of the gauth
group are able to log into the machine without supplying any password at all, while looking at the log, I see these lines:
Jun 15 13:35:57 vagrant-ubuntu-trusty-64 sshd[9836]: Accepted keyboard-interactive/pam for ubuntu from 10.0.2.2 port 55495 ssh2
Jun 15 13:35:57 vagrant-ubuntu-trusty-64 sshd[9836]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
Since it's a vagrant machine it's important to mention that when I connect to the machine for test matters, I run:
ssh localhost -p 2222 -l username
and not
vagrant ssh machine_name
I've also tried to edit /etc/ssh/sshd_config
and edit the PermitRootLogin directive from "without-password" to "no" but to no avail.
I can still login automatically to the machine without supplying any password.
When I remove the "nullok" from the auth line in pam then no user can connect at all and the error message given is:
Permission denied (publickey,keyboard-interactive).
One more thing worth mentioning is that no ssh-keys were exchanged between my Host machine and my Vagrant machine.