<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://dev1galaxy.org/extern.php?action=feed&amp;tid=7657&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / [HowTo] 2FA TOTPs for SSH without google-authenticator.]]></title>
		<link>http://dev1galaxy.org/viewtopic.php?id=7657</link>
		<description><![CDATA[The most recent posts in [HowTo] 2FA TOTPs for SSH without google-authenticator..]]></description>
		<lastBuildDate>Tue, 09 Dec 2025 00:13:34 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[[HowTo] 2FA TOTPs for SSH without google-authenticator.]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=60448#p60448</link>
			<description><![CDATA[<h5>2FA TOTPs</h5><p>##On server side ### you can execute these via SSH as well.</p><p>#Install the required packages for TOTPs:</p><div class="codebox"><pre><code>sudo apt install -y oathtool libpam-oath qrencode keyutils</code></pre></div><p>#Make a backup copy of /etc/ssh/sshd_config</p><div class="codebox"><pre><code>sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config~</code></pre></div><p>#Update the SSH daemon configuration in /etc/ssh/sshd_config</p><div class="codebox"><pre><code>sudo nano /etc/ssh/sshd_config</code></pre></div><p># Make sure this options are enabled<br /><span class="bbc">ChallengeResponseAuthentication yes</span><br /><span class="bbc">KbdInteractiveAuthentication yes</span><br /><span class="bbc">UsePAM yes</span></p><p>#Generate a secure hex secret key for the current user using sha256sum and store it in keyctl to keep the key_id as variable only:</p><div class="codebox"><pre><code>KEY_ID=$(keyctl add user hex_secret $(head -15 /dev/urandom | sha256sum | cut -b 1-30) @s)</code></pre></div><p>&#160; &#160; &#160;<br />#Add the secret to the /etc/users.oath file without actually echoing it:</p><div class="codebox"><pre><code>echo &quot;HOTP/T30/6 $USER - $(keyctl pipe $KEY_ID)&quot; | sudo tee -a /etc/users.oath &gt; /dev/null</code></pre></div><p>&#160; <br />#File /etc/users.oath must be readable and writable only by root to maintain security.</p><div class="codebox"><pre><code>sudo chmod 600 /etc/users.oath</code></pre></div><p>&#160; &#160;<br /># Generate a QR code for the user’s authenticator app:</p><div class="codebox"><pre><code>TKNTITLE=&quot;Your token title here&quot;</code></pre></div><div class="codebox"><pre><code>BASE32_SECRET=$(oathtool --verbose --totp &quot;$(keyctl pipe $KEY_ID)&quot; --digits=6 -w 1 | grep Base32 | cut -d &#039; &#039; -f 3)</code></pre></div><div class="codebox"><pre><code>qrencode --type=ANSIUTF8 &quot;otpauth://totp/$TKNTITLE:$USER@$HOSTNAME?secret=$BASE32_SECRET&amp;issuer=$TKNTITLE&amp;digits=6&quot;</code></pre></div><p>#Scan the previous QR code with your Authenticator app.</p><p>#Configure PAM to use pam_oath.</p><div class="codebox"><pre><code>sudo nano /etc/pam.d/sshd</code></pre></div><p>#add the following two lines at the top of the file, before the @include common-auth line:<br /><span class="bbc"># TOTPs config</span><br /><span class="bbc">auth requisite pam_oath.so usersfile=/etc/users.oath window=20 digits=6</span></p><p>#Restart the SSH service to apply changes:</p><div class="codebox"><pre><code>sudo service ssh restart &amp;&amp; exit</code></pre></div><p># At this point your user can log in via SSH using a dynamically generated OTP from your authenticator app.<br /># Please notice this wont work from any workstations that you have SSH password-less authentication since the purpose for this guide is mostly to prevent brute force password attacks.</p><p>Now from you will have to enter an OTP (Authenticator app) and your user password after, the ssh login screen it will look like:</p><div class="codebox"><pre><code>(user@XX.XXX.X.XXX) One-time password (OATH) for `user&#039;:</code></pre></div><div class="codebox"><pre><code>(user@XX.XXX.X.XXX) Password:</code></pre></div><p># To disable the OTP auth then make the new /etc/ssh/sshd_config as backup, restore the original file and restart ssh service </p><div class="codebox"><pre><code>sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config-2fa</code></pre></div><div class="codebox"><pre><code>sudo cp /etc/ssh/sshd_config~ /etc/ssh/sshd_config</code></pre></div><div class="codebox"><pre><code>sudo service ssh restart</code></pre></div><p># This way you can switch back and fourt if you need.</p><p># Finally lets create a passwordless key based authentication for SSH from your workstation(s) as plan B.</p><h5>Password-less key based authentication</h5><p>## On client/workstation side ##<br /># Create a new ssh key with Ed25519</p><div class="codebox"><pre><code>ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519 -C &quot;$USER@$HOSTNAME-$(date +%F)&quot;</code></pre></div><p>#Enter the same password that you have for your user, this will keep things easier</p><p># Copy the new ssh key to server</p><div class="codebox"><pre><code>ssh-copy-id -i ~/.ssh/id_ed25519.pub $USER@&lt;SERVER_NAME/IP&gt;</code></pre></div><p># This copied the user key to the file ~/.ssh/authorized_keys on server, in other words, to remove password-less authentication for this server then on the same server:</p><div class="codebox"><pre><code>rm ~/.ssh/authorized_keys</code></pre></div><p># Now you can connect like &quot;ssh &lt;SERVER_NAME/IP&gt;&quot; and wont be asked to enter a password or even a 2FA, <br /># this simply to avoid having to use the Authenticator app every time from your own trusted workstations.<br /># or in worst case scenario, if for any reason you can&#039;t use your phone or usb key at the moment.<br /># You can have as many client/workstation keys as you want, just make sure you keep your username as constant.</p><p>Tested with Devuan 6 (Excalibur) but it should work the same with previous versions.</p>]]></description>
			<author><![CDATA[dummy@example.com (joser)]]></author>
			<pubDate>Tue, 09 Dec 2025 00:13:34 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=60448#p60448</guid>
		</item>
	</channel>
</rss>
