<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hpc-wiki.info/hpc/index.php?action=history&amp;feed=atom&amp;title=Admin_Guide_Two-Factor_Authentication_with_OTP</id>
	<title>Admin Guide Two-Factor Authentication with OTP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://hpc-wiki.info/hpc/index.php?action=history&amp;feed=atom&amp;title=Admin_Guide_Two-Factor_Authentication_with_OTP"/>
	<link rel="alternate" type="text/html" href="https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;action=history"/>
	<updated>2026-05-26T11:14:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;diff=4514&amp;oldid=prev</id>
		<title>Mukund-pondkule-6a11@uni-paderborn.de at 18:20, 9 December 2020</title>
		<link rel="alternate" type="text/html" href="https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;diff=4514&amp;oldid=prev"/>
		<updated>2020-12-09T18:20:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:20, 9 December 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC-Admin|Two-Factor Authentication with OTP]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC-Admin|Two-Factor Authentication with OTP]]&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;nowiki /&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC.NRW-Best-Practices|Two-Factor Authentication with OTP]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC.NRW-Best-Practices|Two-Factor Authentication with OTP]]&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;nowiki /&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;{{DISPLAYTITLE:Two-Factor Authentication with OTP (Admin Guide)}}&amp;lt;nowiki /&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= The problem =&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= The problem =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key hpc_wiki:diff::1.12:old-3872:rev-4514 --&gt;
&lt;/table&gt;</summary>
		<author><name>Mukund-pondkule-6a11@uni-paderborn.de</name></author>
	</entry>
	<entry>
		<id>https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;diff=3872&amp;oldid=prev</id>
		<title>Robert-schade-e757@uni-paderborn.de at 15:12, 2 November 2020</title>
		<link rel="alternate" type="text/html" href="https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;diff=3872&amp;oldid=prev"/>
		<updated>2020-11-02T15:12:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:12, 2 November 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC-Admin]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC-Admin&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;|Two-Factor Authentication with OTP&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC.NRW-Best-Practices]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:HPC.NRW-Best-Practices&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;|Two-Factor Authentication with OTP&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= The problem =&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= The problem =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key hpc_wiki:diff::1.12:old-3764:rev-3872 --&gt;
&lt;/table&gt;</summary>
		<author><name>Robert-schade-e757@uni-paderborn.de</name></author>
	</entry>
	<entry>
		<id>https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;diff=3764&amp;oldid=prev</id>
		<title>Robert-schade-e757@uni-paderborn.de: Author Roland Pabel</title>
		<link rel="alternate" type="text/html" href="https://hpc-wiki.info/hpc/index.php?title=Admin_Guide_Two-Factor_Authentication_with_OTP&amp;diff=3764&amp;oldid=prev"/>
		<updated>2020-10-30T18:40:57Z</updated>

		<summary type="html">&lt;p&gt;Author Roland Pabel&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:HPC-Admin]]&lt;br /&gt;
[[Category:HPC.NRW-Best-Practices]]&lt;br /&gt;
&lt;br /&gt;
= The problem =&lt;br /&gt;
&lt;br /&gt;
Login to the head nodes of HPC systems is often just secured by simple (user-generated) passwords, which are also often identical for services like e-mail. A second login factor (2FA) is a second authentication factor independent of the password and using a completely different secret. Also, OTP passwords are only used once at each login and created on demand, valid for only minutes or seconds. This makes hacking these accounts difficult for attackers.&lt;br /&gt;
&lt;br /&gt;
= About OTP =&lt;br /&gt;
&lt;br /&gt;
OTP (one-time-passwords) compute password based on an initial secret (like a private key) and an algorithm. Passwords are computed iteratively, either on demand (at each login) or at specific intervals. The OTP Key is (from a security standpoint) extremely sensitive and must be guarded against theft.&lt;br /&gt;
&lt;br /&gt;
On the server side, &amp;#039;&amp;#039;&amp;#039;oath&amp;#039;&amp;#039;&amp;#039; is needed:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;oathtool.x86_64 : A command line tool for generating and validating OTPs&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;liboath.x86_64 : Library for OATH handling&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;pam_oath.x86_64 : A PAM module for pluggable login authentication for OATH&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the client-side, software for desktop and mobile devices exist:&lt;br /&gt;
&lt;br /&gt;
* [https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;amp;hl=de Google Authenticator]&lt;br /&gt;
* [https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp FreeOTP]&lt;br /&gt;
* [https://apps.apple.com/de/app/freeotp-authenticator/id872559395 FreeOTP for IPhone]&lt;br /&gt;
* …&lt;br /&gt;
&lt;br /&gt;
= The Idea =&lt;br /&gt;
&lt;br /&gt;
Just as with passwords, the generation and distribution of the OTP Key need to be secured. We assume that the user has a password set for the system to log into and use the first login of the user to set up the OTP Key for this user and give him the necessary information to log in again later (with password and OTP). Therefore, on the first login, the user is presented some information and then logged out again.&lt;br /&gt;
&lt;br /&gt;
= The Setup =&lt;br /&gt;
&lt;br /&gt;
After installing &amp;lt;code&amp;gt;oathtool&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PAM&amp;lt;/code&amp;gt; must be adapted:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;/etc/pam.d/ssh&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auth [success=2 default=ignore] pam_succeed_if.so uid = 0                        # skip 2 lines for root&lt;br /&gt;
auth [success=1 default=ignore] pam_succeed_if.so user notingroup otpusers       # ignore users not yet in otpusers&lt;br /&gt;
auth requisite pam_oath.so usersfile=/var/security/auth/users.oath window=20     # accept one of 20 consecutive keys &lt;br /&gt;
 (in case clocks of user and server are out of sync)&amp;lt;/pre&amp;gt;&lt;br /&gt;
and &amp;#039;&amp;#039;&amp;#039;/etc/ssh/sshd_config&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ChallengeResponseAuthentication yes&lt;br /&gt;
PasswordAuthentication no&lt;br /&gt;
UsePAM yes&amp;lt;/pre&amp;gt;&lt;br /&gt;
On first login, a user is not yet a member of group &amp;#039;&amp;#039;&amp;#039;otpusers&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pam_oath.so&amp;#039;&amp;#039;&amp;#039; is thus not run. The login environment then, through scripts in &amp;lt;code&amp;gt;/etc/profile.d/&amp;lt;/code&amp;gt;, generates the OTP Key for the user and puts him/her into the group &amp;#039;&amp;#039;&amp;#039;otpusers&amp;#039;&amp;#039;&amp;#039; and quits:&lt;br /&gt;
&lt;br /&gt;
== &amp;#039;&amp;#039;&amp;#039;/etc/profile.d/create_secret.sh&amp;#039;&amp;#039;&amp;#039; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;####/bin/bash&lt;br /&gt;
# RRZK, 2015-12-10 (CO)&lt;br /&gt;
OATH_FILE=&amp;amp;quot;/var/security/auth/users.oath&amp;amp;quot;&lt;br /&gt;
OTPGROUP=&amp;amp;quot;otpusers&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
ME=$(/usr/bin/whoami)&lt;br /&gt;
#ME=${PAM_USER}&lt;br /&gt;
HOST=${HOSTNAME}&lt;br /&gt;
&lt;br /&gt;
RET=0&lt;br /&gt;
/usr/bin/id -Gn ${ME}|/bin/grep ${OTPGROUP} &amp;amp;gt;/dev/null 2&amp;amp;gt;&amp;amp;amp;1&lt;br /&gt;
RET=$?&lt;br /&gt;
&lt;br /&gt;
if [ ! ${ME} = &amp;amp;quot;root&amp;amp;quot; ] &amp;amp;amp;&amp;amp;amp; [ ${RET} -ne 0 ]; then&lt;br /&gt;
&lt;br /&gt;
# Disable CTRL-C&lt;br /&gt;
trap &amp;#039;&amp;#039; 2&lt;br /&gt;
&lt;br /&gt;
/bin/echo -e &amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
Hello ${ME}&lt;br /&gt;
&lt;br /&gt;
I will generate a TOTP (time based) OATH Secret for you...&lt;br /&gt;
&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
# generate secret&lt;br /&gt;
/bin/echo &amp;amp;quot;... generating secret&amp;amp;quot;&lt;br /&gt;
SECRET=$(/usr/bin/head -10 /dev/urandom | /usr/bin/sha512sum | /bin/cut -b 19-50)&lt;br /&gt;
&lt;br /&gt;
# generate base32 secret &lt;br /&gt;
/bin/echo &amp;amp;quot;... generating base32 secret&amp;amp;quot;&lt;br /&gt;
BASE32=$(/usr/bin/oathtool --totp -v ${SECRET}|/bin/grep &amp;#039;Base32&amp;#039;|/bin/awk &amp;#039;{print $NF}&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# generate qrcode&lt;br /&gt;
/bin/echo &amp;amp;quot;... generating qrcode&amp;amp;quot;&lt;br /&gt;
/usr/bin/qrencode -l H -v 1 --background=FFFFFF -o ${ME}_oath.png &amp;amp;quot;otpauth://totp/${ME}@${HOST}?secret=${BASE32}&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
# insert secret in oath database&lt;br /&gt;
/bin/echo &amp;amp;quot;... adding secret to oath database&amp;amp;quot;&lt;br /&gt;
/bin/echo &amp;amp;quot;... adding user to otpuser group&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
TMPFILE=$(/bin/mktemp ) || exit 1&lt;br /&gt;
/bin/echo -e &amp;amp;quot;HOTP/T30/6\t${ME}\t-\t${SECRET}&amp;amp;quot; &amp;amp;gt; $TMPFILE&lt;br /&gt;
/usr/bin/sudo -u root /usr/local/sbin/add_secret.sh ${TMPFILE} ${OTPGROUP} ${ME}&lt;br /&gt;
/bin/rm -f TMPFILE &lt;br /&gt;
&lt;br /&gt;
/bin/echo &amp;amp;quot;... finished&amp;amp;quot;&lt;br /&gt;
echo &amp;amp;quot;Secret: ${SECRET}&lt;br /&gt;
BASE32 Secret:${BASE32}&amp;amp;quot; &amp;amp;gt; ${ME}_oath.dat&lt;br /&gt;
&lt;br /&gt;
/bin/echo &amp;amp;quot; &lt;br /&gt;
Your Secret is: ${SECRET}&lt;br /&gt;
Your BASE32 Secret is ${BASE32}&lt;br /&gt;
Your QR-Code is: ${ME}_oath.png&lt;br /&gt;
&lt;br /&gt;
Enter your secret in your OTP Token (enter BASE32 without the trailing &amp;#039;=&amp;#039;)&lt;br /&gt;
      or&lt;br /&gt;
Display this file and scan it with your OTP Token APP. (X11Forward only)&lt;br /&gt;
&amp;amp;quot;&lt;br /&gt;
/bin/echo &amp;amp;quot;To display your QR-Code, press &amp;amp;lt;d&amp;amp;gt;&amp;amp;lt;ENTER&amp;amp;gt;&amp;amp;quot;&lt;br /&gt;
read INPUT&lt;br /&gt;
if [ &amp;amp;quot;$INPUT&amp;amp;quot; = &amp;amp;quot;d&amp;amp;quot; ]; then&lt;br /&gt;
  /usr/bin/display ${ME}_oath.png&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
logout&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
The script &amp;#039;&amp;#039;&amp;#039;/usr/local/sbin/add_secret.sh&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#/bin/bash&lt;br /&gt;
# RRZK, 2015-12-10 (CO)&lt;br /&gt;
OATH_FILE=/var/security/auth/users.oath&lt;br /&gt;
&lt;br /&gt;
TMPFILE=$1&lt;br /&gt;
OTPGROUP=$2&lt;br /&gt;
USER=$3&lt;br /&gt;
&lt;br /&gt;
/bin/cat ${TMPFILE} &amp;amp;gt;&amp;amp;gt; ${OATH_FILE}&lt;br /&gt;
/usr/sbin/usermod -a -G ${OTPGROUP} ${USER}&lt;br /&gt;
exit 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
called per &amp;#039;&amp;#039;&amp;#039;sudo&amp;#039;&amp;#039;&amp;#039;(!), is then used to put the user in the group &amp;#039;&amp;#039;&amp;#039;otpusers&amp;#039;&amp;#039;&amp;#039; and save the OTP Key in the database file &amp;#039;&amp;#039;&amp;#039;/var/security/auth/users.oath&amp;#039;&amp;#039;&amp;#039; . Of course, an appropriate &amp;#039;&amp;#039;&amp;#039;sudo&amp;#039;&amp;#039;&amp;#039; rule has to be installed, too.&lt;br /&gt;
&lt;br /&gt;
== Finishing … ==&lt;br /&gt;
&lt;br /&gt;
The script &amp;#039;&amp;#039;&amp;#039;create_secret.sh&amp;#039;&amp;#039;&amp;#039; puts the OTP Keys (text and image) into the home directory of the user: &lt;br /&gt;
- &amp;lt;code&amp;gt;${ME}_oath.dat&amp;lt;/code&amp;gt; &lt;br /&gt;
- &amp;lt;code&amp;gt;${ME}_oath.png&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These files are later removed using &amp;#039;&amp;#039;&amp;#039;cfengine&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
= Example =&lt;br /&gt;
&lt;br /&gt;
== First Login ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Hello test&lt;br /&gt;
&lt;br /&gt;
I will generate a TOTP (time based) OATH Secret for you...&lt;br /&gt;
&lt;br /&gt;
... generating secret&lt;br /&gt;
... generating base32 secret&lt;br /&gt;
... generating qrcode&lt;br /&gt;
... adding secret to oath database&lt;br /&gt;
... adding user to otpuser group&lt;br /&gt;
... finished&lt;br /&gt;
 &lt;br /&gt;
Your Secret is: c6cc87165150391e272194876ebd9ad4&lt;br /&gt;
Your BASE32 Secret is Y3GIOFSRKA4R4JZBSSDW5PM22Q======&lt;br /&gt;
Your QR-Code is: test_oath.png&lt;br /&gt;
&lt;br /&gt;
Enter your secret in your OTP Token (enter BASE32 without the trailing &amp;#039;=&amp;#039;)&lt;br /&gt;
      or&lt;br /&gt;
Display this file and scan it with your OTP Token APP. (X11Forward only)&lt;br /&gt;
&lt;br /&gt;
To display your QR-Code, press &amp;amp;lt;d&amp;amp;gt;&amp;amp;lt;ENTER&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2FA_test_oath.png|200px|QR Code]]&lt;br /&gt;
&lt;br /&gt;
== Second Login ==&lt;br /&gt;
&lt;br /&gt;
The login process then looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rpabel@soliton:~&amp;amp;gt; ssh rpa@hermes.rrz.uni-koeln.de&lt;br /&gt;
One-time password (OATH) for `rpa&amp;#039;: &lt;br /&gt;
Password: &lt;br /&gt;
Last login: Thu Jul  9 14:07:55 2020 from soliton.rrz.uni-koeln.de&lt;br /&gt;
[rpa@hermes ~]$&amp;lt;/pre&amp;gt;&lt;br /&gt;
= Remarks =&lt;br /&gt;
&lt;br /&gt;
* For HPC use, the &amp;#039;&amp;#039;&amp;#039;oath.users&amp;#039;&amp;#039;&amp;#039; should be identical for all login nodes. Put it on the &amp;#039;&amp;#039;&amp;#039;/home&amp;#039;&amp;#039;&amp;#039; parallel filesystem?&lt;br /&gt;
* The group &amp;#039;&amp;#039;&amp;#039;otpusers&amp;#039;&amp;#039;&amp;#039; is there to save just one bit of data (user has OTP secret set up or not). With our current user management, local changes are not desirable. It seems the group was chosen because &amp;#039;&amp;#039;&amp;#039;pam_succeed_if.so&amp;#039;&amp;#039;&amp;#039; can only check a few details at runtime, like UID &amp;amp;amp; groups of the user.&lt;br /&gt;
* When logging in using SSH Keys, OTP could be skipped. This would encourage users to use SSH Keys…&lt;br /&gt;
&lt;br /&gt;
= External links =&lt;br /&gt;
&lt;br /&gt;
* https://spod.cx/blog/two-factor-ssh-auth-with-pam_oath-google-authenticator.shtml&lt;/div&gt;</summary>
		<author><name>Robert-schade-e757@uni-paderborn.de</name></author>
	</entry>
</feed>