<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Peek Read Info (Posts about ssh)</title><link>https://peekread.info/</link><description></description><atom:link href="https://peekread.info/tags/ssh.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2024 &lt;a href="mailto:dugite-code@peekread.info"&gt;Dugite-Code&lt;/a&gt; 
&lt;a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
width="88px" height="31px" style="border-width:0; margin-bottom:12px;"
src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Wed, 14 Feb 2024 06:33:09 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>SSH Login Notifications with Gotify</title><link>https://peekread.info/tech/20190716-ssh-login-notifications-with-gotify/</link><dc:creator>Dugite-Code</dc:creator><description>&lt;p&gt;&lt;/p&gt;&lt;div class="d-flex position-relative pt-3 pb-3"&gt;
    &lt;div class="flex-shrink-0 me-3"&gt;
        &lt;img data-pagefind-meta="image[src], image_alt[alt]" style="height:89px;" src="https://peekread.info/images/2019/gotify.png" alt="Gotify is a simple server for sending and receiving messages"&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;p class="mt-3"&gt;&lt;/p&gt;&lt;p&gt;Inspired by &lt;a href="https://8192.one/post/ssh_login_notification_signal/"&gt;this post&lt;/a&gt; I decided to add a notification on my phone every time an ssh session began on my servers. Seeing as I make use of &lt;a href="https://gotify.net"&gt;Gotify&lt;/a&gt; for selfhosted push notifications I used that rather than signal.&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;First I created created the file &lt;code&gt;/usr/local/bin/sshnotif&lt;/code&gt;. At the top you can add your own token and Gotify url&lt;/p&gt;
&lt;p&gt;Update: I had to push the current time back a full minute in order to improve consistency. I'll defiantly want to revisit this at a later date&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="ch"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;exec&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;/dev/null&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#Hide output&lt;/span&gt;

&lt;span class="nv"&gt;Gotify_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'https://example.tld/gotify'&lt;/span&gt;
&lt;span class="nv"&gt;Gotify_Token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'gotify-app-token'&lt;/span&gt;

notify&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nv"&gt;now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"-60 seconds"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;+%s&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#Get current time minus 60 seconds&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nv"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="nv"&gt;SECONDS&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#Set 30s Timeout for loop&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$SECONDS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-lt&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt;

&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="nv"&gt;SSHdate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;who&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;pts&lt;span class="p"&gt;|&lt;/span&gt;tail&lt;span class="w"&gt; &lt;/span&gt;-1&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;awk&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'{print $3, $4}'&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;+%s&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#Check for the latest SSH session&lt;/span&gt;

&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$SSHdate&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-ge&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$now&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#Once who is updated continue with sending Notification&lt;/span&gt;

&lt;span class="w"&gt;                        &lt;/span&gt;&lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"SSH Login for &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;/bin/hostname&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="w"&gt;                        &lt;/span&gt;&lt;span class="nv"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;/usr/bin/who&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;pts&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="w"&gt;                        &lt;/span&gt;/usr/bin/curl&lt;span class="w"&gt; &lt;/span&gt;-X&lt;span class="w"&gt; &lt;/span&gt;POST&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;                                &lt;/span&gt;-F&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"title=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;                                &lt;/span&gt;-F&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"message=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;                                &lt;/span&gt;-F&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"priority=5"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;                                &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;Gotify_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/message?token=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;Gotify_Token&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="w"&gt;                        &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

notify&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;#Run in background to prevent holding up the login process&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Run the command &lt;code&gt;chmod +x /usr/local/bin/sshnotif&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In the file &lt;code&gt;/etc/pam.d/sshd&lt;/code&gt; add the following line&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="c1"&gt;# note optional is set to prevent ssh login failure&lt;/span&gt;
session&lt;span class="w"&gt; &lt;/span&gt;optional&lt;span class="w"&gt; &lt;/span&gt;pam_exec.so&lt;span class="w"&gt; &lt;/span&gt;/usr/local/bin/sshnotif
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I now get a nice notification with all the open SSH sessions listed. Unlike the post on &lt;a href="https://peekread.info/tech/20190716-ssh-login-notifications-with-gotify/8192.one"&gt;8192.one&lt;/a&gt; I didn't want any IP address resolution using an online service. I plan on integrating the MaxMind &lt;a href="https://dev.maxmind.com/geoip/geoip2/geolite2/"&gt;GeoLite2 database&lt;/a&gt; at some point. However as I already have &lt;a href="https://peekread.info/tech/20190716-ssh-login-notifications-with-gotify/graylog.org"&gt;Graylog&lt;/a&gt; set up to do this it's not a high priority for me.&lt;/p&gt;
&lt;p&gt;Thanks for the shoutout: https://zerosec.xyz/posts/gotify-notifications/&lt;/p&gt;</description><category>gotify</category><category>security</category><category>ssh</category><guid>https://peekread.info/tech/20190716-ssh-login-notifications-with-gotify/</guid><pubDate>Mon, 15 Jul 2019 16:00:00 GMT</pubDate></item><item><title>Locking your ssh port with fwknop</title><link>https://peekread.info/tech/20190513-fwknop/</link><dc:creator>Dugite-Code</dc:creator><description>&lt;p&gt;&lt;strong&gt;UPDATED&lt;/strong&gt; Thanks to sk@0x in the comments for the bits I missed&lt;/p&gt;
&lt;p&gt;In my &lt;a href="https://peekread.info/posts/20190429-dropbear/"&gt;last post&lt;/a&gt; I described how I decrypt my home server remotely with ssh. Today I would like to share how I like to lock/unlock my ssh port with an encrypted port knocking implementation fwknop&lt;/p&gt;
&lt;h2&gt;The issue with port knocking&lt;/h2&gt;
&lt;p&gt;On the face of it port knocking looks like a good idea. Lock down your ssh port until you need it, avoiding any zero day issues with the ssh protocols. The problem is this, port knocking is sent in the clear over the network. Anyone looking can see your knock "code", much like if you had a secret door knock some one around the corner could heard the pattern of your knocks.&lt;/p&gt;
&lt;p&gt;This is where fwknop comes in, it's SPA (Single Packet Authorization) cannot be re-sent it is one time only. Not to mention it's faster as you are only sending the one packet.&lt;/p&gt;
&lt;p&gt;The main issue I had with fwknop is by default you have to specify the source IP address you want to be able to access your server. I found this to be quite painful to set-up, so I found a simple way around the issue.&lt;/p&gt;
&lt;p&gt;Note: this only works if you are blocking ports by default. I use UFW to simplify that process. See this &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04"&gt;Digital Ocean&lt;/a&gt; tutorial on the basics of UFW&lt;/p&gt;
&lt;h3&gt;Server Side:&lt;/h3&gt;
&lt;p&gt;In Debian based systems fwknop is split into fwknop-client and fwknop-server. We will want both of them&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;sudo apt install fwknop-server fwknop-client
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;First we need to enable the fwknop server in the &lt;code&gt;/etc/default/fwknop-server&lt;/code&gt; file. by changing the line &lt;code&gt;START_DAEMON="no"&lt;/code&gt;&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="gh"&gt;#&lt;/span&gt; Default settings for fwknopd.

&lt;span class="gh"&gt;#&lt;/span&gt; Change it to yes if you would like fwknopd to be started at boot time.
&lt;span class="gh"&gt;#&lt;/span&gt;
# START_DAEMON="no"
START_DAEMON="yes"

&lt;span class="gh"&gt;#&lt;/span&gt; Add any options you would like to pass to the daemon when started
&lt;span class="gh"&gt;#&lt;/span&gt; For example if you would like to add an override file for your setup, this
&lt;span class="gh"&gt;#&lt;/span&gt; can be achieved this way:
&lt;span class="gh"&gt;#&lt;/span&gt;
#     DAEMON_ARGS="--override-config /root/fwknopd.override.conf"
DAEMON_ARGS=""
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Next we need to set up the basic config rules on the server found in &lt;code&gt;/etc/fwknop/fwknopd.conf&lt;/code&gt; Debian and Ubuntu have changed the default interface name from eth0 to enp3s0 so we have to set that. We can also change the listening port here.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;PCAP_INTF               enp3s0;

&lt;span class="gh"&gt;#&lt;/span&gt; change your port to your desired listening port.
PCAP_FILTER                 udp port 62201;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we use fwknop to generate our key's. We could use GpG here, but I didn't feel the extra encryption brings much to the table as we are only opening the ssh port and I have public key authentication and TOTP enabled.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;fwknop -A tcp/22 -D example.tld --key-gen --use-hmac --save-rc-stanza
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You can now find the KEY_BASE64 and HMAC_KEY_BASE64 in &lt;code&gt;~/.fwknoprc&lt;/code&gt; we will need these for the &lt;code&gt;/etc/fwknop/access.conf&lt;/code&gt; file and the client.&lt;/p&gt;
&lt;p&gt;In the &lt;code&gt;/etc/fwknop/access.conf&lt;/code&gt; file. Note: I substituted the iptable commands for ufw commands. We don't have to worry about our ssh session being kicked as once it's connected the CMD_CYCLE_CLOSE (at least with ufw) won't close the existing connection.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;SOURCE                          ANY

&lt;span class="gh"&gt;#&lt;/span&gt; Limit the Ports able to be opened
OPEN_PORTS                      tcp/22

&lt;span class="gh"&gt;#&lt;/span&gt; Keys from ~/.fwknoprc
KEY_BASE64                      [...]
HMAC_KEY_BASE64                 [...]

&lt;span class="gh"&gt;#&lt;/span&gt; Optionally use iptables
&lt;span class="gh"&gt;#&lt;/span&gt; CMD_CYCLE_OPEN                /sbin/iptables -A INPUT -p $PROTO --dport $PORT -j ACCEPT
&lt;span class="gh"&gt;#&lt;/span&gt; CMD_CYCLE_CLOSE               iptables -D INPUT -p $PROTO --dport $PORT -j ACCEPT

CMD_CYCLE_OPEN                  /usr/sbin/ufw allow $PORT
CMD_CYCLE_CLOSE                 /usr/sbin/ufw delete allow $PORT

&lt;span class="gh"&gt;#&lt;/span&gt; Default cycle time Mandatory for CMD_CYCLE_OPEN/CLOSE
CMD_CYCLE_TIMER                 180
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;A word of warning, fwknop can run arbitrary commands if &lt;code&gt;ENABLE_CMD_EXEC&lt;/code&gt; is enabled. I don't see why you would ever really want to do that. You can also run any bash script from &lt;code&gt;CMD_CYCLE_OPEN&lt;/code&gt; and &lt;code&gt;CMD_CYCLE_CLOSE&lt;/code&gt; with the optional variables &lt;code&gt;$PROTO&lt;/code&gt;, &lt;code&gt;$PORT&lt;/code&gt; and &lt;code&gt;$SRC&lt;/code&gt;. You can potentially get yourself in a lot of trouble if you do this so proceed with caution.&lt;/p&gt;
&lt;p&gt;Now we need to setup the systemd file &lt;code&gt;/etc/systemd/system/fwknop-server.service&lt;/code&gt;. Note: on a ubuntu (18.04.4 LTS) install I had to create the folder &lt;code&gt;/var/fwknop/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; sk@0x in the comments also mentioned the PID file needs to be in &lt;code&gt;/run/fwknop&lt;/code&gt; dir in Ubuntu 20.04&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;Firewall Knock Operator Daemon&lt;/span&gt;
&lt;span class="na"&gt;After&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;network-online.target&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;forking&lt;/span&gt;
&lt;span class="na"&gt;PIDFile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/var/fwknop/fwknopd.pid&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/sbin/fwknopd&lt;/span&gt;
&lt;span class="na"&gt;ExecReload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/bin/kill -HUP $MAINPID&lt;/span&gt;

&lt;span class="k"&gt;[Install]&lt;/span&gt;
&lt;span class="na"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;multi-user.target&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then we just enable and start the service&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;sudo systemctl enable fwknop-server.service &amp;amp;&amp;amp; sudo systemctl start fwknop-server.service
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Running &lt;code&gt;sudo systemctl status fwknop-server.service&lt;/code&gt; should now show you the service is active &lt;code&gt;Active: active (running)&lt;/code&gt;. Currently if you have already allowed port 22 with ufw it will stay open until the first time you cycle fwknop with a client.&lt;/p&gt;
&lt;h3&gt;Client Side:&lt;/h3&gt;
&lt;p&gt;You have three options &lt;a href="https://manpages.debian.org/stretch/fwknop-client/fwknop.8.en.html"&gt;fwknop-client&lt;/a&gt;, fwknop2 on android - &lt;a href="https://f-droid.org/en/packages/org.cipherdyne.fwknop2/"&gt;[F-Droid]&lt;/a&gt; - &lt;a href="https://play.google.com/store/apps/details?id=org.cipherdyne.fwknop2&amp;amp;hl=en_US"&gt;[Google play]&lt;/a&gt; or &lt;a href="https://github.com/jp-bennett/fwknop-gui"&gt;fwknop-gui&lt;/a&gt; available on Windows, Mac and Linux&lt;/p&gt;
&lt;p&gt;In fwknop2 and fwknop-gui:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;KEY_BASE64 -&amp;gt; Rijndael Key&lt;/li&gt;
&lt;li&gt;Key Is Base 64 - Checkbox below key entry&lt;/li&gt;
&lt;li&gt;HMAC_KEY_BASE64 -&amp;gt; HMAC Key&lt;/li&gt;
&lt;li&gt;HMAC Is Base 64 - Checkbox below key entry&lt;/li&gt;
&lt;li&gt;Allow IP - This can be anything as we are ignoring this setting&lt;/li&gt;
&lt;li&gt;Access Ports: tcp/22&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Firewall timeout is in seconds and can be anything as long as it's long enough for you to authenticate. Remember if you have the same set-up as I do, you wont get kicked after the timeout.&lt;/p&gt;
&lt;p&gt;And there we go a nice locked ssh port. You will now have to send a SLA to your server prior to connecting with your ssh client.&lt;/p&gt;</description><category>security</category><category>ssh</category><guid>https://peekread.info/tech/20190513-fwknop/</guid><pubDate>Mon, 13 May 2019 00:00:00 GMT</pubDate></item><item><title>Securing My Server With Dropbear SSH</title><link>https://peekread.info/tech/20190429-dropbear/</link><dc:creator>Dugite-Code</dc:creator><description>&lt;p&gt;Having a small home server I've always wanted to encrypt my files, however I have never wanted to be locked out if I'm far away. Enter dropbear ssh. A small light weight ssh server already packaged in debian to work prior to decryption.&lt;/p&gt;
&lt;h2&gt;Install&lt;/h2&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;sudo apt update &amp;amp;&amp;amp; sudo apt install dropbear-initramfs
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Note: initramfs will kick up an error after installing dropbear-initramfs. This is solved after adding your public key&lt;/p&gt;
&lt;h3&gt;Add your ssh key&lt;/h3&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh-keygen -t rsa -b 4096 -o -a 100 -f ~/.ssh/dropbear.id_rsa
sudo cat ~/.ssh/dropbear.id_rsa.pub &amp;gt; /etc/dropbear-initramfs/authorized_keys
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Changing the port&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;/etc/dropbear-initramfs/config&lt;/code&gt;&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;DROPBEAR_OPTIONS="-p 3000"
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;A little extra security&lt;/h3&gt;
&lt;p&gt;You can further secure dropbear by disabling forwarding and limiting it to only executing the &lt;code&gt;cryptroot-unlock&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;Just add &lt;code&gt;no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="/bin/cryptroot-unlock"&lt;/code&gt; to the &lt;code&gt;authorized_keys&lt;/code&gt; file in front of the ssh public key&lt;/p&gt;
&lt;p&gt;It should look something like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="/bin/cryptroot-unlock" ssh-rsa A AQQQQQJJQQHx[...]
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Finishing up&lt;/h3&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;sudo update-initramfs -u
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://linux.die.net/man/8/dropbear"&gt;See the dropbear manpage for further details&lt;/a&gt;&lt;/p&gt;</description><category>security</category><category>ssh</category><guid>https://peekread.info/tech/20190429-dropbear/</guid><pubDate>Mon, 29 Apr 2019 00:00:00 GMT</pubDate></item><item><title>Better SSH Management with Keepass and Putty</title><link>https://peekread.info/tech/20190415-ssh/</link><dc:creator>Dugite-Code</dc:creator><description>&lt;p&gt;Out of the box keepass recognizes the URI &lt;code&gt;ssh://&lt;/code&gt; and will open it with putty. However it is limited, you can't change ports from the default port 22 nor can you save a convenient list of port forwards. Thankfully this is something you can change.&lt;/p&gt;
&lt;p&gt;Things you will need:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://keepass.info"&gt;Keepass&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://putty.org"&gt;Putty&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/dlech/KeeAgent"&gt;Keeagent&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Alternativly you can do an easy install with the windows package manager &lt;a href="https://chocolatey.org/install"&gt;chocolatey&lt;/a&gt;&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;choco&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;putty.install&lt;span class="w"&gt; &lt;/span&gt;keepass.install&lt;span class="w"&gt; &lt;/span&gt;keepass-plugin-keeagent&lt;span class="w"&gt; &lt;/span&gt;-y
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;URL overrides&lt;/h3&gt;
&lt;p&gt;We will now define a new &lt;code&gt;ssh://&lt;/code&gt; override globaly in keepass. It is possible to also do so per entry, for portability, however I do not use this feature as I run linux at home and use a separate override on that system.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Tools -&amp;gt; Options&lt;/li&gt;
&lt;li&gt;Integration tab&lt;/li&gt;
&lt;li&gt;URL Overrides&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="" class="mx-auto d-block img-fluid" loading="lazy" src="https://peekread.info/images/2019/0415-ssh/image01.png"&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click the add button&lt;/li&gt;
&lt;li&gt;Enter ssh in the Scheme field&lt;/li&gt;
&lt;li&gt;Enter: &lt;code&gt;cmd://putty {T-REPLACE-RX:/{S:Forwards}/\{S:Forwards\}/ /} -P {T-REPLACE-RX:/{BASE:PORT}/-1/22 /} {BASE:HOST} -l {USERNAME}&lt;/code&gt; in the url override field.
    Note: add &lt;code&gt;-pw {PASSWORD}&lt;/code&gt; to the end if you wish to auto submit your password. Just be aware this could be considered slightly insecure.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="" class="mx-auto d-block img-fluid" loading="lazy" src="https://peekread.info/images/2019/0415-ssh/image02.png"&gt;&lt;/p&gt;
&lt;h3&gt;The Keepass entry&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Create an entry as you normally would adding the &lt;code&gt;ssh://&lt;/code&gt; URL&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note: to add a port just use &lt;code&gt;ssh://example.tld:222&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="" class="mx-auto d-block img-fluid" loading="lazy" src="https://peekread.info/images/2019/0415-ssh/image03.png"&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If you need port forwards add then under the Advanced tab as a String Field entry in the following format: &lt;code&gt;-L 6080:127.0.0.1:6080 -L 444:10.1.1.1:444&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="" class="mx-auto d-block img-fluid" loading="lazy" src="https://peekread.info/images/2019/0415-ssh/image04.png"&gt;&lt;/p&gt;
&lt;p&gt;Now when you open the url you will have your putty session with port changes and port forwards.&lt;/p&gt;
&lt;h3&gt;Breaking it down&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;cmd://putty&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Opens putty via a shell command&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;{T-REPLACE-RX:/{S:Forwards}/\{S:Forwards\}/ /}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If the string field Forwards doesn't exist delete the string &lt;code&gt;{S:Forwards}&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-P {T-REPLACE-RX:/{BASE:PORT}/-1/22 /}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;{BASE:PORT}&lt;/code&gt; placeholder returns &lt;code&gt;-1&lt;/code&gt; If a port is not defined. If this happens we should replace it with the default ssh port 22&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;{BASE:HOST}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The Hostname/IP address part of the URL&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-l {USERNAME} -pw {PASSWORD}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Login with the username and (optionally) password of the entry&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</description><category>security</category><category>ssh</category><guid>https://peekread.info/tech/20190415-ssh/</guid><pubDate>Mon, 15 Apr 2019 00:00:00 GMT</pubDate></item></channel></rss>