Table of Contents
SSH is great. It lets you log into your Linux machine from anywhere. But what if you want to make it more secure? Two-factor authentication (2FA) adds an extra layer of protection. One cool way to do that is using Authy along with PAM, the Pluggable Authentication Module. Sounds fancy, right? But it’s not that hard.
So you set things up… and then bam — you see an error: “Could not generate token.” What’s going on? Don’t panic. We’re going to fix it, step by step. And we’ll have fun doing it!
Authy is a 2FA app. It helps protect your logins. You get a code on your phone, and you use that after your usual SSH password. Even if someone has your password, they can’t get in without your phone. Magic!
You can integrate Authy into your Linux login process using PAM. That means it becomes part of how Linux checks who you are when you log in via SSH. Sounds cool? It is.
Authy doesn’t have a native PAM module anymore managed publicly by them. But good news! There are community tools, and you can also use the older authy-pam module for test purposes. Please note: use with caution in production environments.
install.sh.Done? Nice. Now let’s hook it into SSH.
To start using Authy for SSH, you’ll edit the PAM config for SSH. This is usually at:
/etc/pam.d/sshd Add this line at the top:
auth required pam_authy.so Then, restart SSH:
sudo systemctl restart sshd Now when you SSH in, Authy will ask you for a token from your phone. Sweet!
Suddenly, Authy isn’t working. You’re being told: “Could not generate token”. What gives?
This error generally means the PAM module can’t contact the Authy API. It can’t authenticate you with Authy. There are several reasons this can happen:
The Authy PAM module needs your Authy API key to talk to the service. Make sure this key is correct and accessible by PAM. Usually it’s placed in:
/etc/authy/api.key Check file permissions:
sudo chmod 600 /etc/authy/api.key
sudo chown root:root /etc/authy/api.key Restart SSH after any changes.
Each Linux user that logs in must be registered with Authy. This means they need an Authy ID in:
/etc/authy/users/username If the file is missing — you guessed it — Authy won’t know what to do. Create it using:
echo <AUTHY_ID> > /etc/authy/users/username Replace <AUTHY_ID> with the actual one given by Authy API after registering the user programmatically or through your portal.
Authy needs to reach out to an API server. If your SSH server has no internet access or DNS issues, you won’t get a token.
curl https://api.authy.com/var/log/auth.log for errorsIf you see timeouts, check your /etc/resolv.conf and any firewall rules.
To find out more, increase logging. In /etc/pam.d/sshd, modify the line to:
auth required pam_authy.so debug This outputs debug info to /var/log/auth.log or /var/log/secure, depending on your distro.
Look for lines about missing IDs or permission issues. They’re usually pretty clear.
Some PAM modules don’t pass environment variables by default. If Authy is expecting environment variables to be set (like a proxy or certificate location), PAM may not provide them.
Try setting them in /etc/environment or a script that sets them system-wide on boot.
If you’ve tried everything and still get the error, try running pam_authy_test from the command line to manually test the module:
sudo /usr/sbin/pam_authy_test username This gives more info and often points right at the issue. Be sure to replace “username” with the actual one.
If you’re adding lots of users, here’s a simple shell function:
#!/bin/bash
read -p "Enter username: " username
read -p "Enter Authy ID: " authyid
sudo mkdir -p /etc/authy/users
echo $authyid | sudo tee /etc/authy/users/$username
echo "User $username registered with Authy!" Adding Authy to your SSH login boosts security a lot. PAM integration makes it seamless. If you ever see that “Could not generate token” message, you now know what to check.
Just remember:
Now your SSH is not just secure — it’s Authy-secure!
Happy securing!
Discord is where a lot of fun happens! Whether you're chatting with friends while playing…
Maintaining a tModLoader server is a rewarding experience for Terraria enthusiasts who want to explore…
In today’s hybrid work culture, ensuring secure and seamless access to data across cloud platforms…
Audio drift is one of the most frustrating issues faced by mobile video editors, particularly…
If you’ve ever played Minecraft, you’ve probably heard that there are two main versions: Java…
Project Zomboid is a thrilling open-world survival game that immerses players in a brutal post-apocalyptic…