http://www.sbarjatiya.com/notes_wiki/index.php?title=CentOS_7.x_Systemd_based_reverse_SSH_service&feed=atom&action=history
CentOS 7.x Systemd based reverse SSH service - Revision history
2024-03-28T09:45:47Z
Revision history for this page on the wiki
MediaWiki 1.37.1
http://www.sbarjatiya.com/notes_wiki/index.php?title=CentOS_7.x_Systemd_based_reverse_SSH_service&diff=7381&oldid=prev
Saurabh at 16:31, 28 August 2022
2022-08-28T16:31:13Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:31, 28 August 2022</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="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;"><div><del style="font-weight: bold; text-decoration: none;"><yambe:breadcrumb self="Systemd based reverse SSH service"</del>><del style="font-weight: bold; text-decoration: none;">CentOS_7</del>.<del style="font-weight: bold; text-decoration: none;">x_OpenSSH_server</del>|OpenSSH server<del style="font-weight: bold; text-decoration: none;"></yambe:breadcrumb</del>></div></td><td class="diff-marker" data-marker="+"></td><td style="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;"><div><ins style="font-weight: bold; text-decoration: none;">[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] </ins>> <ins style="font-weight: bold; text-decoration: none;">[[CentOS 7</ins>.<ins style="font-weight: bold; text-decoration: none;">x Remote access</ins>|<ins style="font-weight: bold; text-decoration: none;">Remote Access]] > [[CentOS 7.x </ins>OpenSSH server<ins style="font-weight: bold; text-decoration: none;">|OpenSSH]] </ins>> <ins style="font-weight: bold; text-decoration: none;">[[</ins>CentOS 7.x Systemd based reverse SSH service<ins style="font-weight: bold; text-decoration: none;">]]</ins></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="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;"><div><del style="font-weight: bold; text-decoration: none;">=</del>CentOS 7.x Systemd based reverse SSH service<del style="font-weight: bold; text-decoration: none;">=</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><br/></td><td class="diff-marker"></td><td style="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;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><div>'''There is newer article on this at [[CentOS 8.x Systemd based reverse ssh tunnel service]]'''</div></td><td class="diff-marker"></td><td style="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;"><div>'''There is newer article on this at [[CentOS 8.x Systemd based reverse ssh tunnel service]]'''</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l69">Line 69:</td>
<td colspan="2" class="diff-lineno">Line 68:</td></tr>
<tr><td class="diff-marker"></td><td style="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;"><br/></td><td class="diff-marker"></td><td style="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;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><br/></td><td class="diff-marker"></td><td style="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;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="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;"><div><del style="font-weight: bold; text-decoration: none;"><yambe:breadcrumb self="Systemd based reverse SSH service"</del>><del style="font-weight: bold; text-decoration: none;">CentOS_7</del>.<del style="font-weight: bold; text-decoration: none;">x_OpenSSH_server</del>|OpenSSH server<del style="font-weight: bold; text-decoration: none;"></yambe:breadcrumb</del>></div></td><td class="diff-marker" data-marker="+"></td><td style="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;"><div><ins style="font-weight: bold; text-decoration: none;">[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] </ins>> <ins style="font-weight: bold; text-decoration: none;">[[CentOS 7</ins>.<ins style="font-weight: bold; text-decoration: none;">x Remote access</ins>|<ins style="font-weight: bold; text-decoration: none;">Remote Access]] > [[CentOS 7.x </ins>OpenSSH server<ins style="font-weight: bold; text-decoration: none;">|OpenSSH]] </ins>> <ins style="font-weight: bold; text-decoration: none;">[[CentOS 7.x Systemd based reverse SSH service]]</ins></div></td></tr>
</table>
Saurabh
http://www.sbarjatiya.com/notes_wiki/index.php?title=CentOS_7.x_Systemd_based_reverse_SSH_service&diff=6289&oldid=prev
Saurabh at 08:05, 15 May 2022
2022-05-15T08:05:05Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 08:05, 15 May 2022</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker"></td><td style="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;"><div><yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb></div></td><td class="diff-marker"></td><td style="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;"><div><yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb></div></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><div>=CentOS 7.x Systemd based reverse SSH service=</div></td><td class="diff-marker"></td><td style="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;"><div>=CentOS 7.x Systemd based reverse SSH service=</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="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;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="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;"><div><ins style="font-weight: bold; text-decoration: none;">'''There is newer article on this at [[CentOS 8.x Systemd based reverse ssh tunnel service]]'''</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><br/></td><td class="diff-marker"></td><td style="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;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><div>In case anydesk/teamviewer are proving unreliable and reverse ssh is desirable to an internal server behind NAT via a public server, then use following steps to set it up:</div></td><td class="diff-marker"></td><td style="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;"><div>In case anydesk/teamviewer are proving unreliable and reverse ssh is desirable to an internal server behind NAT via a public server, then use following steps to set it up:</div></td></tr>
</table>
Saurabh
http://www.sbarjatiya.com/notes_wiki/index.php?title=CentOS_7.x_Systemd_based_reverse_SSH_service&diff=4231&oldid=prev
Saurabh at 09:35, 6 June 2019
2019-06-06T09:35:02Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 09:35, 6 June 2019</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker"></td><td style="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;"><div><yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb></div></td><td class="diff-marker"></td><td style="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;"><div><yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="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;"><div><ins style="font-weight: bold; text-decoration: none;">=CentOS 7.x Systemd based reverse SSH service=</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><br/></td><td class="diff-marker"></td><td style="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;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="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;"><div>In case anydesk/teamviewer are proving unreliable and reverse ssh is desirable to an internal server behind NAT via a public server, then use following steps to set it up:</div></td><td class="diff-marker"></td><td style="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;"><div>In case anydesk/teamviewer are proving unreliable and reverse ssh is desirable to an internal server behind NAT via a public server, then use following steps to set it up:</div></td></tr>
</table>
Saurabh
http://www.sbarjatiya.com/notes_wiki/index.php?title=CentOS_7.x_Systemd_based_reverse_SSH_service&diff=4225&oldid=prev
Saurabh: Created page with "<yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb> In case anydesk/teamviewer are proving unreliable and r..."
2019-06-06T09:25:33Z
<p>Created page with "<yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb> In case anydesk/teamviewer are proving unreliable and r..."</p>
<p><b>New page</b></p><div><yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb><br />
<br />
In case anydesk/teamviewer are proving unreliable and reverse ssh is desirable to an internal server behind NAT via a public server, then use following steps to set it up:<br />
* Create ssh-keys '''on both servers'''<br />
* Establish trusted ssh from local server to public server and vice-versa '''on both servers'''<br />
* Create <tt>/etc/systemd/system/files-reverse-ssh.service</tt> with following contents on '''internal server''':<br />
<pre><br />
[Unit]<br />
Description=files-reverse-ssh service<br />
After=network.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=/bin/sh /root/files-reverse-ssh.sh<br />
Restart=always<br />
User=root<br />
Group=root<br />
<br />
[Install]<br />
WantedBy=multi-user.target <br />
</pre><br />
* chmod 744 /etc/systemd/system/files-reverse-ssh.service<br />
* Create <tt>/root/files-reverse-ssh.sh</tt> with following contents '''on internal server''':<br />
<pre><br />
#!/bin/bash<br />
<br />
SERVER="files.sunilsanjay.com"<br />
RPORT=3333<br />
<br />
while sleep 60; do<br />
#Count number of existing connections<br />
COUNT=$(ps aux | grep root@$SERVER | wc -l)<br />
if (( "$COUNT" > 2 )); then<br />
echo "SSH already connected, not doing anything extra"<br />
else<br />
# Check SSH Connction is available or not <br />
status=$(ssh -o BatchMode=yes -o ConnectTimeout=30 root@$SERVER echo ok 2>&1)<br />
<br />
#If available connect to remote server<br />
if [[ $status == ok ]] ; then<br />
echo "Going to start new SSH connection in background"<br />
/usr/bin/ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=1 -R $RPORT:127.0.0.1:22 root@$SERVER -N &<br />
elif [[ $status == "Permission denied"* ]] ; then<br />
echo "Not able to connect due to permission denied error"<br />
else<br />
echo "Error: $status"<br />
fi<br />
fi<br />
done <br />
exit 0<br />
</pre><br />
* Set required permissions and start service<br />
<pre><br />
chmod 744 /root/files-reverse-ssh.sh<br />
systemctl daemon-reload<br />
systemctl enable files-reverse-ssh<br />
systemctl start files-reverse-ssh<br />
systemctl status files-reverse-ssh<br />
</pre><br />
<br />
<br />
Refer:<br />
* https://unix.stackexchange.com/questions/34004/how-does-tcp-keepalive-work-in-ssh for closing SSH connection if Internet connection is lost.<br />
<br />
<br />
<br />
<br />
<yambe:breadcrumb self="Systemd based reverse SSH service">CentOS_7.x_OpenSSH_server|OpenSSH server</yambe:breadcrumb></div>
Saurabh