# Installing Google Authenticator for SSH, OpenConnect, OpenVPN?

**URL:** <https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439>\
**Category:** For Developers\
**Created:** [February 15, 2019, 7:21pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439 "2019-02-15T19:21:17Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![unitelife](https://forum.openwrt.org/letter_avatar/unitelife/32/6_449c533f586939b6e5f246632a46421f.png) [@unitelife](https://forum.openwrt.org/u/unitelife)\
**Post date:** [February 15, 2019, 7:21pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/1 "2019-02-15T19:21:17Z")

</div>

Hello Community,

I am trying to get Google Authenticator to be configured with my ssh, Luci, and OpenVPN. Is this possible? I have researched the following forums and websites and it looks like it has been discussed before.

- [old archived openwrt google auth post](https://forum.archive.openwrt.org/viewtopic.php?id=38905)

- [Two factor authentification using openconnect VPN](https://forum.openwrt.org/t/two-factor-authentification-using-openconnect-vpn/8613)

I noticed there was an ipk developed for Barrier Breaker and Chaos Calmer at one time.

- [libpam-google-authenticator\_1.0-1\_ar71xx.ipk](https://archive.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/libpam-google-authenticator_1.0-1_ar71xx.ipk)

and there is a supported required package:

- libpam 1.2.0-2 The Linux-PAM Pluggable Authentication Modules.

I was going to try these how-tos with alterations to match the openwrt environment but was not sure about the packages involved vs what they use on regular linux distros:

- [Old post for reference on google auth](https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-two-factor-authentication)

- [new how-to for google auth on ubuntu](https://www.digitalocean.com/community/tutorials/how-to-set-up-multi-factor-authentication-for-ssh-on-ubuntu-16-04)

- [configuring google auth on openvpn](https://medium.com/we-have-all-been-there/using-google-authenticator-mfa-with-openvpn-on-ubuntu-16-04-774e4acc2852)

I tried checking the OpenWrt wiki and documentation section for any new information on this task but couldn't find anything. Would it be safe to try and work with this old build on a test router? Any tips or advice would greatly be appreciated.

Sincerely,

A humbly committed student

---

<div class="post-metadata">

**Author:** ![jeff](https://forum.openwrt.org/letter_avatar/jeff/32/6_449c533f586939b6e5f246632a46421f.png) [@jeff](https://forum.openwrt.org/u/jeff)\
**Post date:** [February 15, 2019, 7:24pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/2 "2019-02-15T19:24:44Z")

</div>

> [@unitelife](#):
>
> Would it be safe to try and work with this old build on a test router?

Unlikely -- far too many things have changed in the last several years / releases to just install the packages.

It's "a bit incongruous" to talk about security with years-old, known-insecure releases, so you should be working with `18.01` or `master`.

Might be some good info at

> [@Two factor authentification using openconnect VPN](https://forum.openwrt.org/t/two-factor-authentification-using-openconnect-vpn/8613):
>
> Hi all, I would like to add two factor authentification (\> TOTP; via Google Authenticator) to my VPN (using openconnect) but I could not find any information online how to do that. The only thing I found was here: and here: [http://ocserv.gitlab.io/www/manual.html#heading8](http://ocserv.gitlab.io/www/manual.html#heading8) What I understand so far is that this should be somehow included in /etc/config/ocserv. Please correct me if I am wrong. Thanks, Marcel.

---

<div class="post-metadata">

**Author:** ![slh](https://forum.openwrt.org/user_avatar/forum.openwrt.org/slh/32/113591_2.png) [@slh](https://forum.openwrt.org/u/slh)\
**Post date:** [February 15, 2019, 9:04pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/3 "2019-02-15T21:04:15Z")

</div>

> [@MFA on Openwrt SSH & LuCi](https://forum.openwrt.org/t/mfa-on-openwrt-ssh-luci/29941):
>
> I'm curious if there are plans to add MultiFactor Authentication to LuCi like Google Authenticator and if it's already possible to do multifactor authentication when SSHing to openwrt router. Thanks

The same problems apply here, you need urgent device access most, whenever the 'internet is down' and while your router doesn't have the slightest idea what time it is (rebooted, no RTC, no battery backed RTC).

---

<div class="post-metadata">

**Author:** ![unitelife](https://forum.openwrt.org/letter_avatar/unitelife/32/6_449c533f586939b6e5f246632a46421f.png) [@unitelife](https://forum.openwrt.org/u/unitelife)\
**Post date:** [February 15, 2019, 9:19pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/4 "2019-02-15T21:19:08Z")

</div>

Thanks @jeff  
Since there was a build for google auth at one time, how hard would it be to port it over?

---

<div class="post-metadata">

**Author:** ![jeff](https://forum.openwrt.org/letter_avatar/jeff/32/6_449c533f586939b6e5f246632a46421f.png) [@jeff](https://forum.openwrt.org/u/jeff)\
**Post date:** [February 15, 2019, 9:24pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/5 "2019-02-15T21:24:24Z")

</div>

Very significant changes in OpenWrt run-time architecture since Chaos Calmer. It could be straightforward, it could be a challenge. Looking at the old Makefiles and current ones would be the first steps.

_(Though I concur that requiring Internet connectivity to access a device that is critical to you to have Internet connectivity is asking for trouble.)_

---

<div class="post-metadata">

**Author:** ![KernelKurtz](https://forum.openwrt.org/letter_avatar/kernelkurtz/32/6_449c533f586939b6e5f246632a46421f.png) [@KernelKurtz](https://forum.openwrt.org/u/KernelKurtz)\
**Post date:** [February 20, 2019, 2:11am UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/6 "2019-02-20T02:11:45Z")

</div>

I've been researching this topic a bit myself lately, as I too would like to get Google Authenticator working (but only for OpenVPN, not for SSH or Luci that are only accessible locally). From my reading it should only be the additional GA libpam module that is needed, I \_think\_OpenVPN should not need to be rebuilt to support libpam in general. I've built lots of software from source on Linux, but I've never cross compiled anything. Over the next while I'm going to try and follow the docs to create a build environment in a VM and do some experimentation. I'm sure I will have questions, so I'll be back LOL.

---

<div class="post-metadata">

**Author:** ![KernelKurtz](https://forum.openwrt.org/letter_avatar/kernelkurtz/32/6_449c533f586939b6e5f246632a46421f.png) [@KernelKurtz](https://forum.openwrt.org/u/KernelKurtz)\
**Post date:** [March 3, 2019, 3:34pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/7 "2019-03-03T15:34:28Z")

</div>

So maybe someone here can help with this.

I've created a Debian 9 VM, and I've successfully built a toolchain for my device, as well as an image I will never use. Now I'm trying to cross compile google-authenticator-libpam, but configure fails looking for the PAM header files. The header files do exist in

> ~/openwrt/build\_dir/target-aarch64\_cortex-a72\_musl/Linux-PAM-1.3.1/libpam/include/security$ ls  
> pam\_appl.h \_pam\_compat.h pam\_ext.h \_pam\_macros.h pam\_modules.h pam\_modutil.h \_pam\_types.h

but configure obviously does not find them there. Do I need to move these somewhere else? Create symlinks? Pass it to the ./configure script?

I am a complete newbie at this cross compiling thing so be kind 🙂

---

<div class="post-metadata">

**Author:** ![KernelKurtz](https://forum.openwrt.org/letter_avatar/kernelkurtz/32/6_449c533f586939b6e5f246632a46421f.png) [@KernelKurtz](https://forum.openwrt.org/u/KernelKurtz)\
**Post date:** [March 3, 2019, 5:50pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/8 "2019-03-03T17:50:40Z")

</div>

So I tried passing that directory to CPPFLAGS, and configure with -host=aarch64-openwrt-linux-musl and make afterward both completed without errors.

I have no idea if this is going to work, but hey, just killing time on a Sunday.....

Edit: Did not actually cross compile. Got an x86\_64 binary.

Back to the drawing board LOL.

---

<div class="post-metadata">

**Author:** ![slh](https://forum.openwrt.org/user_avatar/forum.openwrt.org/slh/32/113591_2.png) [@slh](https://forum.openwrt.org/u/slh)\
**Post date:** [March 3, 2019, 8:22pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/9 "2019-03-03T20:22:14Z")

</div>

The best strategy is usually to package it up for OpenWrt properly - and then to just build it as part of the normal image build. Cross-compiling has lots of quirks and OpenWrt's buildroot takes care of a lot of things automatically you'd usually have to handle manually.

---

<div class="post-metadata">

**Author:** ![KernelKurtz](https://forum.openwrt.org/letter_avatar/kernelkurtz/32/6_449c533f586939b6e5f246632a46421f.png) [@KernelKurtz](https://forum.openwrt.org/u/KernelKurtz)\
**Post date:** [March 3, 2019, 8:53pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/10 "2019-03-03T20:53:59Z")

</div>

Thanks slh. That's good advice. I'm a network guy and while basic building from source on Linux is pretty familiar I'm out of my depth here. I foolishly figured if I had a cross compiler it would be easy to just build one application for my own use.

Actually, making a package looks even more intimidating, but any time I've spent is still a good learning experience regardless. I've a lot more insight into what creating this system entails now. Props to the people doing it.

---

<div class="post-metadata">

**Author:** ![KernelKurtz](https://forum.openwrt.org/letter_avatar/kernelkurtz/32/6_449c533f586939b6e5f246632a46421f.png) [@KernelKurtz](https://forum.openwrt.org/u/KernelKurtz)\
**Post date:** [March 13, 2019, 6:18pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/11 "2019-03-13T18:18:48Z")

</div>

I'm still picking away at this when I have some spare time. I copied the header and pam library files into the staging directory where configure could find them, and built it with them statically linked so I would hopefully not have to worry about them later. It seems to have cross compiled OK with no errors

> blair@Debian1:~/google-authenticator-libpam$ file google-authenticator  
> google-authenticator: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped

But alas, it does not run when I move it to the OpenWRT router, giving an error;

> ./google-authenticator: line 1: syntax error: unexpected ")"

For all the amazing things OpenWRT can do, the lack of support for 2FA does not seem like it should be an insurmountable thing to fix. I'm now looking at trying to create a package system makefile instead. Will post my results in that attempt eventually.

---

<div class="post-metadata">

**Author:** ![redorbluepill](https://forum.openwrt.org/user_avatar/forum.openwrt.org/redorbluepill/32/10449_2.png) [@redorbluepill](https://forum.openwrt.org/u/redorbluepill)\
**Post date:** [March 22, 2019, 4:23pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/12 "2019-03-22T16:23:27Z")

</div>

Hi, I had a similar problem (for OpenSSH)... and I think I solved it.

Published the Makefile to Github: [https://github.com/redorbluepill/openwrt-google-authenticator](https://github.com/redorbluepill/openwrt-google-authenticator)

I have implemented this for OpenSSH as follows (as an example):

1. Save the makefile in a package folder of your choosing (see the "Hello World" example on [OpenWRT.org](http://OpenWRT.org)) and add this to the feeds.conf.default file;
2. "./scripts/feeds clean"
3. "./scripts/feeds update -a"
4. "./scripts/feeds install openssh-server-pam"
5. "make menuconfig" and select the packages "openssh-server-pam" in Network - SSH and "libpam-google-authenticator" in Utilities. Make sure to select the M option and not \*.
6. Save the config and run "make -j$(nproc \* 1.5)"
7. Move the packages from //src/bin/packages// to the OpenWrt router and install / force install

You will need to do all the additional configs for Openssh though, like moving Dropbear to another port and change some of the config for Openssh.  
Works fine on my OpenWrt 18.06.2 on a BT HomeHub 5A (target: mips\_24k)

I hope this helps for the Google Authenticator bit. I have not tested this for OpenVPN.

Cheers

---

<div class="post-metadata">

**Author:** ![slh](https://forum.openwrt.org/user_avatar/forum.openwrt.org/slh/32/113591_2.png) [@slh](https://forum.openwrt.org/u/slh)\
**Post date:** [March 22, 2019, 5:40pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/13 "2019-03-22T17:40:38Z")

</div>

Do yourself a favour and try to check this now, before you deploy it into productive use - before declaring victory.

- switch off the router (remove the power cable)
- remove the xDSL/ WAN cable, so the router won't be able to connect to the internet (no way to query ntp)
- power up the router and try to connect using google-authenticator

Believe me, you need administrative access most, whenever the internet access is failing and these devices don't have an rtc (even less a battery backed rtc).

---

<div class="post-metadata">

**Author:** ![redorbluepill](https://forum.openwrt.org/user_avatar/forum.openwrt.org/redorbluepill/32/10449_2.png) [@redorbluepill](https://forum.openwrt.org/u/redorbluepill)\
**Post date:** [March 22, 2019, 6:13pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/14 "2019-03-22T18:13:58Z")

</div>

That is a very good point. 😣

So maybe still a good option for people with an OpenVPN need.

And if implemented for OpenSSH, maybe have one of the following:

1. Have public-key authentication enabled and this set up for your main computer; or
2. a separate DropBear instance listening only on local lan on a separate port, like 5522.

But that all seems to defeat the initial purpose.  
Appreciate the warning...

Could be useful for the following setup though?

- OpenSSH with Google-Authenticator for login from WAN (if you need this)
- Dropbear (without Google-Authenticator) instance bound to LAN for emergency.

---

<div class="post-metadata">

**Author:** ![lucize](https://forum.openwrt.org/user_avatar/forum.openwrt.org/lucize/32/2512_2.png) [@lucize](https://forum.openwrt.org/u/lucize)\
**Post date:** [March 22, 2019, 6:59pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/15 "2019-03-22T18:59:11Z")

</div>

I made a PR and is now in the master tree

---

<div class="post-metadata">

**Author:** ![KernelKurtz](https://forum.openwrt.org/letter_avatar/kernelkurtz/32/6_449c533f586939b6e5f246632a46421f.png) [@KernelKurtz](https://forum.openwrt.org/u/KernelKurtz)\
**Post date:** [March 23, 2019, 8:28pm UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/16 "2019-03-23T20:28:34Z")

</div>

Thank you redorbluepill and lucize!!! I'll see if I can get this working now with OpenVPN and report back in a bit.

Obviously having the correct time is critical to use these token based auth systems. I'm only interested in using them for remote access as a more flexible "something you have" than certs. In theory if there is internet to allow remote access there should be NTP as well. I would obviously not recommend using this internally when internet/NTP may not be available. Using an internal NTP server with an RTC could be a work around for that though. GA lets you choose a token code range that allows for several minutes of drift should that be necessary.

---

<div class="post-metadata">

**Author:** ![noseratio](https://forum.openwrt.org/user_avatar/forum.openwrt.org/noseratio/32/19898_2.png) [@noseratio](https://forum.openwrt.org/u/noseratio)\
**Post date:** [February 8, 2021, 9:40am UTC](https://forum.openwrt.org/t/installing-google-authenticator-for-ssh-openconnect-openvpn/31439/17 "2021-02-08T09:40:36Z")

</div>

I've got MFA working for OpenSSH with OpenWrt v19.07.06, [the howto](https://forum.openwrt.org/t/howto-openssh-with-mfa-on-openwrt-19-07-x-using-google-authenticator/88025).
