{"id":66,"date":"2012-08-10T14:34:04","date_gmt":"2012-08-10T10:34:04","guid":{"rendered":"http:\/\/xxxl.co.za\/?p=66"},"modified":"2023-03-14T19:04:21","modified_gmt":"2023-03-14T15:04:21","slug":"safe-ssh-tunnel-based-mysql-updates-well-i-think","status":"publish","type":"post","link":"https:\/\/xxxl.co.za\/?p=66","title":{"rendered":"Safe SSH tunnel based Mysql updates (Well i think?)"},"content":{"rendered":"<p>Server:<br \/>\nSetup user with key based authentication:<br \/>\n<code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">useradd -s \/bin\/false myuser\r\nmkdir \/home\/myuser\/.ssh\r\ntouch \/home\/myuser\/.ssh\/authorized_keys\r\nchown -R myuser:myuser \/home\/myuser\/.ssh\r\nchmod 755 \/home\/myuser\/.ssh\r\nchmod 600 \/home\/myuser\/.ssh\/authorized_keys<\/pre>\n<p><\/code><\/p>\n<p>Client side:<br \/>\nInstall rpmforge repo and autossh.<br \/>\n<code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">rpm --import http:\/\/apt.sw.be\/RPM-GPG-KEY.dag.txt\r\nwget http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm\r\nor\r\nwget http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.i386.rpm\r\n\r\nrpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm\r\nrpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm\r\nsed -i &quot;s\/enabled = 1\/enabled = 0\/&quot; \/etc\/yum.repos.d\/rpmforge.repo\r\nyum -y install --enablerepo=rpmforge autossh\r\nssh-keygen -t rsa<\/pre>\n<p><\/code><br \/>\nSet up an RSA key pair as root on each client, leaving all questions blank:<br \/>\n<code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">ssh-keygen -t rsa\r\nroot@local# ssh-keygen -t rsa\r\nGenerating public\/private rsa key pair.\r\nEnter file in which to save the key (\/var\/root\/.ssh\/id_rsa):\r\nEnter passphrase (empty for no passphrase):\r\nEnter same passphrase again:\r\nYour identification has been saved in \/var\/root\/.ssh\/id_rsa.\r\nYour public key has been saved in \/var\/root\/.ssh\/id_rsa.pub.\r\nThe key fingerprint is:\r\nXX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX root@myhost.local<\/pre>\n<p><\/code><br \/>\nNow scp this to your server:<br \/>\n<code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">scp -P 22 \/root\/.ssh\/id_rsa.pub root@myserver.com:\/tmp\/myuser.local_rsa.pub<\/pre>\n<p><\/code><br \/>\nOn Server: Add to your authorized_keys.<br \/>\n<code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cat \/tmp\/myuser.local_rsa.pub &gt;&gt; \/home\/myuser\/.ssh\/authorized_keys<\/pre>\n<p><\/code><br \/>\nClient side:<br \/>\ncreate \/etc\/init.d\/startautossh on client with contents below. \/\/This example nables connection to server MySQL port 3306 on localhost port 3307.<br \/>\n<code><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># pidfile: \/var\/run\/autossh.pid\r\n# @since 2012-02-22 15:31:47\r\n# @author Roderick Derks\r\n# Source function library\r\n. \/etc\/init.d\/functions\r\n\r\nprog=&quot;autossh&quot;\r\nautossh=&quot;\/usr\/bin\/autossh&quot;\r\nRETVAL=0\r\nAUTOSSH_PIDFILE=\/var\/run\/autossh.pid\r\n\r\n# Tunnel configuration\r\nLOCAL_PORT_LISTEN=3307\r\nREMOTE_DESTINATION_PORT=3306\r\nUSER=myuser\r\nREMOTE_DESTINATION_IP=yourserver.com\r\nREMOTE_SSH_SERVER_PORT=22\r\n\r\nstart() {\r\necho -n $&quot;Starting $prog: &quot;\r\nif &#x5B; ! -e $AUTOSSH_PIDFILE ]; then\r\nAUTOSSH_PIDFILE=$AUTOSSH_PIDFILE;export AUTOSSH_PIDFILE\r\nautossh -M 0 -q -f -N -o &quot;ServerAliveInterval 60&quot; -o &quot;ServerAliveCountMax 3&quot; -L $LOCAL_PORT_LISTEN:localhost:$REMOTE_DESTINATION_PORT -p $REMOTE_SSH_SERVER_PORT\u00a0 $USER@$REMOTE_DESTINATION_IP\r\n\r\nRETVAL=$?\r\nelse\r\nRETVAL=1\r\necho_failure\r\necho pid file still exists $AUTOSSH_PIDFILE\r\nfi\r\necho\r\n&#x5B; $RETVAL -eq 0 ] touch \/var\/lock\/subsys\/$prog\r\nreturn $RETVAL\r\n}\r\n\r\nstop() {\r\necho -n $&quot;Stopping $prog: &quot;\r\nkillproc $autossh\r\nRETVAL=$?\r\necho\r\n&#x5B; $RETVAL -eq 0 ] rm -f \/var\/lock\/subsys\/$prog rm -f $AUTOSSH_PIDFILE\r\nreturn $RETVAL\r\n}\r\n\r\ncase &quot;$1&quot; in\r\nstart)\r\nstart\r\n;;\r\nstop)\r\nstop\r\n;;\r\nrestart)\r\nstop\r\nstart\r\n;;\r\nstatus)\r\nstatus $autossh\r\nRETVAL=$?\r\n;;\r\n*)\r\n\r\necho $&quot;Usage: $0 {start|stop|restart|status}&quot;\r\nesac\r\nRETVAL=1\r\nClient side: (make script executeable):\r\nchmod +x \/etc\/init.d\/startautossh<\/pre>\n<p><\/code><br \/>\nReferences:<br \/>\nhttp:\/\/www.r71.nl\/kb\/technical\/348-autossh-init-script<br \/>\nhttp:\/\/tychoish.com\/rhizome\/persistent-ssh-tunels-with-autossh\/<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"NgNnrCEly5\"><p><a href=\"https:\/\/www.jbmurphy.com\/2011\/04\/29\/autossh-on-centos\/\">AutoSSH on CentOS<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;AutoSSH on CentOS&#8221; &#8212; jbmurphy.com\" src=\"https:\/\/www.jbmurphy.com\/2011\/04\/29\/autossh-on-centos\/embed\/#?secret=2fOyZ18bSv#?secret=NgNnrCEly5\" data-secret=\"NgNnrCEly5\" width=\"474\" height=\"267\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><br \/>\nhttp:\/\/chxo.com\/be2\/20040511_5667.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Server: Setup user with key based authentication: useradd -s \/bin\/false myuser mkdir \/home\/myuser\/.ssh touch \/home\/myuser\/.ssh\/authorized_keys chown -R myuser:myuser \/home\/myuser\/.ssh chmod 755 \/home\/myuser\/.ssh chmod 600 \/home\/myuser\/.ssh\/authorized_keys Client side: Install rpmforge repo and autossh. rpm &#8211;import http:\/\/apt.sw.be\/RPM-GPG-KEY.dag.txt wget http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm or wget http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.i386.rpm rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm sed -i &quot;s\/enabled = 1\/enabled = 0\/&quot; \/etc\/yum.repos.d\/rpmforge.repo yum &hellip; <a href=\"https:\/\/xxxl.co.za\/?p=66\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Safe SSH tunnel based Mysql updates (Well i think?)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/xxxl.co.za\/index.php?rest_route=\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xxxl.co.za\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xxxl.co.za\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xxxl.co.za\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xxxl.co.za\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66"}],"version-history":[{"count":58,"href":"https:\/\/xxxl.co.za\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/xxxl.co.za\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions\/337"}],"wp:attachment":[{"href":"https:\/\/xxxl.co.za\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xxxl.co.za\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xxxl.co.za\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}