What to do when 2FA won't allow you into your Linux servers

4 months ago 23
PR Distribution

If two-factor authentication logins connected your Linux servers are giving you fits, Jack Wallen has the solution for you.


Image: iStockphoto/Jirsak

Recently, I had an incidental wherever a two-factor authentication-enabled Linux server wouldn't let maine successful via SSH. Fortunately, I had carnal entree to the server, truthful it wasn't a implicit disaster. Had I not been capable to log into the instrumentality connected site, I would person had to number connected idiosyncratic on-premise to instrumentality attraction of the situation. In immoderate cases, that would not do.

SEE: 5 Linux server distributions you should beryllium using (TechRepublic Premium)

It didn't instrumentality maine agelong to fig retired what the occupation was, and it's an contented that is astir apt much rampant than you think. Once I solved the issue, everything was bully to go, and I was capable to log backmost in, via SSH.

The problem, you see, is each astir time. Or, successful the lawsuit of this server, the incorrect time. 2FA codes are time-sensitive, truthful they trust connected the server and the app you're utilizing to make the codes being successful sync with regards to time. If either server oregon instrumentality displays the incorrect time, chances are beauteous bully 2FA volition not let you access. More often than not, the contented lies connected the server side.

To that end, what bash you do? It's rather simple. Let maine amusement you.

What you'll need: The lone happening you request to marque this hole is simply a idiosyncratic with sudo privileges. That's it, let's close that server's time.

How to acceptable the clip portion connected a Linux server

This is wherever the astir communal occupation lies. Unless you acceptable the timezone decently during the installation of the operating system, it's apt to beryllium incorrect. How bash you hole it? Open a terminal connected your Linux server and contented the command:


The output of the supra bid volition not lone database the machine's configured clip zone, but the section time, cosmopolitan time, RTC time, if the strategy timepiece is synchronized, and if the NTP work is active.

The archetypal happening we request to bash is close the clip portion (if it is incorrect). To bash that, you indispensable cognize however the strategy displays timezones. For that, contented the command:

timedatectl list-timezones

Search done the output to find your clip zone. It volition beryllium listed as:


If a authorities lone has a azygous timezone, it volition beryllium listed as:


Once you cognize your afloat clip zone, you tin acceptable it with the command:

sudo timedatectl set-timezone TIMEZONE

Where TIMEZONE is your afloat timezone.

How to acceptable the clip connected a Linux server

Your champion stake with mounting the clip is utilizing NTP, arsenic this volition automatically support your clip successful sync. How you bash this volition beryllium connected the organisation you usage for your servers. For RHEL-based servers (such arsenic AlmaLinux and Rocky Linux), you instal chrony with the command:

sudo dnf instal chrony -y

For an Ubuntu-based server, you instal ntp with the command:

sudo apt-get instal ntp -y

Enable chrony with the commands:

sudo systemctl commencement chronyd sudo systemctl alteration chronyd

Enable ntp with the commands:

sudo systemctl commencement ntp sudo systemctl alteration ntp

Give the strategy a infinitesimal oregon truthful to sync, and your clip should beryllium close (check it with the day command). You should present beryllium capable to log into those servers with 2FA.

Hopefully, this solved your SSH/2FA login issues. It should, arsenic astir apt 90% of 2FA login issues are centered astir out-of-sync clocks connected the server end. And though your timepiece mightiness person been close erstwhile you archetypal setup 2FA, if you're not utilizing an automatic time-sync daemon and your clip portion was incorrect, that server volition endure from clip drift, and yet 2FA volition not let you in.

Open Source Weekly Newsletter

You don't privation to miss our tips, tutorials, and commentary connected the Linux OS and unfastened root applications. Delivered Tuesdays

Sign up today

Also spot

Read Entire Article