{"id":467565,"date":"2025-07-18T22:46:44","date_gmt":"2025-07-18T22:46:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=467565"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=467565","title":{"rendered":"<span>\u0421\u043a\u0440\u0438\u043f\u0442-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440: \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u043f\u0430\u0432\u0448\u0438\u0445 SSH-\u0441\u0435\u0441\u0441\u0438\u0439<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u0432\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0438\u043b\u0438 \u0438\u0437\u0443\u0447\u0430\u0435\u0442\u0435 \u043b\u043e\u0433\u0438 &#8212; \u0438 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0412\u0441\u0435 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0443\u043b\u0435\u0442\u0443\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f, \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0432\u0441\u0451 \u0437\u0430\u043d\u043e\u0432\u043e.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u043a\u0440\u0438\u043f\u0442-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0434\u043b\u044f SSH, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u043e\u0431\u0440\u044b\u0432\u0430\u0445<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e \u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043a\u043e\u043c\u0430\u043d\u0434<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 tmux\/screen \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u0432 Telegram<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0434\u043b\u044f Bash \u0438 PowerShell<\/p>\n<\/li>\n<\/ul>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>SSH-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;\u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439&#187; \u0432\u043e\u043a\u0440\u0443\u0433 SSH-\u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043e\u0431\u0440\u044b\u0432\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443, \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u0431\u044d\u043a\u0430\u043f \u043d\u0430 3 \u0447\u0430\u0441\u0430. \u0411\u0435\u0437 \u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0440\u044b\u0432\u0430 \u0412\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e, \u043d\u043e \u043d\u0435 \u0432 \u0441\u0442\u0438\u0443\u0430\u0446\u0438\u0438 \u0441 \u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u043e\u043c. \u041e\u043d \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u044d\u043a\u0430\u043f\u0430 \u0441 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u043e\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0451\u043b \u043e\u0431\u0440\u044b\u0432.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0435 \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u0435: \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0438\u043b\u0435 Zabbix, Nagios \u0438 \u0442\u0434. \u041e\u043d \u043b\u0438\u0448\u044c \u0434\u0430\u0451\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u043c\u0438 \u043a \u0441\u0431\u043e\u044f\u043c. \u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0439 VPS, \u0433\u0434\u0435 Zabbix (\u0438 \u043f\u0440\u043e\u0447\u0438\u0435) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0441\u0447\u0443\u0440 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<h3>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b SSH-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u0430<\/h3>\n<h4>1. \u0414\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u0440\u044b\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/h4>\n<p>SSH \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 2 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p><code>ServerAliveInterval<\/code> (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;0&#187; &#8212; \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043e)<\/p>\n<ul>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u043c\u0435\u0436\u0434\u0443 keepalive-\u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<p><code>ServerAliveCountMax<\/code> (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;3&#187;)<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043b-\u0432\u043e \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0435\u0440\u0435\u0434 \u0440\u0430\u0437\u0440\u044b\u0432\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u0423\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>ServerAliveInterval<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0451\u0442\u0430:<\/strong><\/p>\n<pre><code class=\"bash\">ssh -o ServerAliveInterval=20 -o ServerAliveCountMax=4 user@host<\/code><\/pre>\n<ul>\n<li>\n<p>20 x 4 = 80 \u0441\u0435\u043a\u0443\u043d\u0434 \u0431\u0435\u0437 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u041c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h4>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0438\u0436\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0446\u0438\u043a\u043b <code>while true<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">while true; do   ssh -o ServerAliveInterval=30 user@host   if [ $? -eq 0 ]; then     break # \u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0432\u044b\u0445\u043e\u0434   else     sleep 5 # \u041f\u0430\u0443\u0437\u0430 \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u043e\u0439   fi done<\/code><\/pre>\n<p><strong>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 SSH (0 &#8212; \u0443\u0441\u043f\u0435\u0445, \u0438\u043d\u044b\u0435 &#8212; \u043e\u0448\u0438\u0431\u043a\u0430)<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u0446\u0438\u043a\u043b\u0430 \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<h4>Bash-\u0441\u043a\u0440\u0438\u043f\u0442<\/h4>\n<pre><code class=\"bash\">#!\/bin\/bash  SERVER=\"user@example.com\" SSH_OPTS=\"-o ServerAliveInterval=30 -o ServerAliveCountMax=3\" DELAY=5  while true; do     echo \"[$(date +'%H:%M:%S')] \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a $SERVER...\"     ssh $SSH_OPTS $SERVER          if [ $? -eq 0 ]; then         echo \"[$(date +'%H:%M:%S')] \u0421\u0435\u0441\u0441\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430\"         break     else         echo \"[$(date +'%H:%M:%S')] \u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u041f\u043e\u0432\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 $DELAY \u0441\u0435\u043a...\"         sleep $DELAY     fi done<\/code><\/pre>\n<h4>Bash-\u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c tmux<\/h4>\n<pre><code class=\"bash\">#!\/bin\/bash  SERVER=\"user@example.com\" SESSION=\"remote_work\" SSH_OPTS=\"-o ServerAliveInterval=30 -o ServerAliveCountMax=3\"  while true; do     echo \"[$(date +'%H:%M:%S')] \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0441\u0435\u0441\u0441\u0438\u0438 $SESSION \u043d\u0430 $SERVER...\"     ssh -t $SSH_OPTS $SERVER \"tmux attach -t $SESSION || tmux new -s $SESSION\"          if [ $? -eq 0 ]; then         break     else         sleep 5     fi done<\/code><\/pre>\n<h4>PowerShell-\u0441\u043a\u0440\u0438\u043f\u0442<\/h4>\n<pre><code class=\"powershell\">$SERVER = \"user@example.com\" $SSH_OPTS = \"-o ServerAliveInterval=30 -o ServerAliveCountMax=3\" $DELAY = 5  while ($true) {     Write-Host \"[$(Get-Date -Format 'HH:mm:ss')] \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a $SERVER...\"     ssh $SSH_OPTS $SERVER          if ($LASTEXITCODE -eq 0) {         break     } else {         Start-Sleep -Seconds $DELAY     } }<\/code><\/pre>\n<h4>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h4>\n<ol>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"bash\">nano ssh_reconnect.sh chmod +x ssh_reconnect.sh<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c:<\/p>\n<pre><code class=\"bash\">.\/ssh_reconnect.sh &gt;&gt; ssh_log.txt 2&gt;&amp;1<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435:<\/p>\n<pre><code class=\"bash\">nohup .\/ssh_reconnect.sh &gt; \/dev\/null 2&gt;&amp;1 &amp;<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>\u0422\u0430\u043a\u0436\u0435, \u0435\u0449\u0451 \u043f\u0430\u0440\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/strong><\/p>\n<ol>\n<li>\n<p>Telegram-\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">TELEGRAM_API=\"https:\/\/api.telegram.org\/bot{TOKEN}\/sendMessage\" CHAT_ID=\"12345\" MESSAGE=\"\u041e\u0448\u0438\u0431\u043a\u0430 SSH \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 $SERVER\"  curl -s -X POST $TELEGRAM_API -d chat_id=$CHAT_ID -d text=\"$MESSAGE\"<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0410\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a \u0447\u0435\u0440\u0435\u0437 crontab:<\/p>\n<pre><code class=\"bash\">@reboot \/path\/to\/ssh_reconnect.sh<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<pre><code class=\"bash\">ssh $SERVER \"cat &gt;&gt; ~\/.persistent_history\"<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438<\/h4>\n<ol>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 tmux \u0438\u043b\u0438 screen<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f ServerAliveInterval \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f terminal multiplexers<\/p>\n<\/li>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u0438\u0447\u0438\u043d \u0440\u0430\u0437\u0440\u044b\u0432\u043e\u0432<\/p>\n<\/li>\n<\/ol>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u044b\u0432\u043e\u0432 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<p><em>P.S. \u042f \u0432\u0435\u0434\u0443 \u0441\u0432\u043e\u044e \u0433\u0440\u0443\u043f\u043f\u0443 \u0432<\/em>\u00a0<a href=\"https:\/\/t.me\/automate_today\" rel=\"noopener noreferrer nofollow\"><em>\u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c<\/em><\/a><em>, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435\u0445, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u043c\u0438\u0440\u0435 IT.<\/em>  <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/927234\/\"> https:\/\/habr.com\/ru\/articles\/927234\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u0432\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0438\u043b\u0438 \u0438\u0437\u0443\u0447\u0430\u0435\u0442\u0435 \u043b\u043e\u0433\u0438 &#8212; \u0438 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0412\u0441\u0435 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0443\u043b\u0435\u0442\u0443\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f, \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u043e\u0442\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0432\u0441\u0451 \u0437\u0430\u043d\u043e\u0432\u043e.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u043a\u0440\u0438\u043f\u0442-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0434\u043b\u044f SSH, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u043e\u0431\u0440\u044b\u0432\u0430\u0445<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e \u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043a\u043e\u043c\u0430\u043d\u0434<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 tmux\/screen \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u0432 Telegram<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0434\u043b\u044f Bash \u0438 PowerShell<\/p>\n<\/li>\n<\/ul>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>SSH-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;\u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439&#187; \u0432\u043e\u043a\u0440\u0443\u0433 SSH-\u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043e\u0431\u0440\u044b\u0432\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443, \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u0431\u044d\u043a\u0430\u043f \u043d\u0430 3 \u0447\u0430\u0441\u0430. \u0411\u0435\u0437 \u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0440\u044b\u0432\u0430 \u0412\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e, \u043d\u043e \u043d\u0435 \u0432 \u0441\u0442\u0438\u0443\u0430\u0446\u0438\u0438 \u0441 \u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u043e\u043c. \u041e\u043d \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u044d\u043a\u0430\u043f\u0430 \u0441 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u043e\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0451\u043b \u043e\u0431\u0440\u044b\u0432.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0435 \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u0435: \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0438\u043b\u0435 Zabbix, Nagios \u0438 \u0442\u0434. \u041e\u043d \u043b\u0438\u0448\u044c \u0434\u0430\u0451\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u043c\u0438 \u043a \u0441\u0431\u043e\u044f\u043c. \u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0439 VPS, \u0433\u0434\u0435 Zabbix (\u0438 \u043f\u0440\u043e\u0447\u0438\u0435) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0441\u0447\u0443\u0440 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<h3>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b SSH-\u0440\u0435\u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u0430<\/h3>\n<h4>1. \u0414\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u0440\u044b\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/h4>\n<p>SSH \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 2 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p><code>ServerAliveInterval<\/code> (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;0&#187; &#8212; \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043e)<\/p>\n<ul>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u043c\u0435\u0436\u0434\u0443 keepalive-\u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<p><code>ServerAliveCountMax<\/code> (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;3&#187;)<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043b-\u0432\u043e \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0435\u0440\u0435\u0434 \u0440\u0430\u0437\u0440\u044b\u0432\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u0423\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>ServerAliveInterval<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0451\u0442\u0430:<\/strong><\/p>\n<pre><code class=\"bash\">ssh -o ServerAliveInterval=20 -o ServerAliveCountMax=4 user@host<\/code><\/pre>\n<ul>\n<li>\n<p>20 x 4 = 80 \u0441\u0435\u043a\u0443\u043d\u0434 \u0431\u0435\u0437 \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u041c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h4>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0438\u0436\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0446\u0438\u043a\u043b <code>while true<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">while true; do   ssh -o ServerAliveInterval=30 user@host   if [ $? -eq 0 ]; then     break # \u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0432\u044b\u0445\u043e\u0434   else     sleep 5 # \u041f\u0430\u0443\u0437\u0430 \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u043e\u0439   fi done<\/code><\/pre>\n<p><strong>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 SSH (0 &#8212; \u0443\u0441\u043f\u0435\u0445, \u0438\u043d\u044b\u0435 &#8212; \u043e\u0448\u0438\u0431\u043a\u0430)<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u0446\u0438\u043a\u043b\u0430 \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<h4>Bash-\u0441\u043a\u0440\u0438\u043f\u0442<\/h4>\n<pre><code class=\"bash\">#!\/bin\/bash  SERVER=\"user@example.com\" SSH_OPTS=\"-o ServerAliveInterval=30 -o ServerAliveCountMax=3\" DELAY=5  while true; do     echo \"[$(date +'%H:%M:%S')] \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a $SERVER...\"     ssh $SSH_OPTS $SERVER          if [ $? -eq 0 ]; then         echo \"[$(date +'%H:%M:%S')] \u0421\u0435\u0441\u0441\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430\"         break     else         echo \"[$(date +'%H:%M:%S')] \u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u041f\u043e\u0432\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 $DELAY \u0441\u0435\u043a...\"         sleep $DELAY     fi done<\/code><\/pre>\n<h4>Bash-\u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c tmux<\/h4>\n<pre><code class=\"bash\">#!\/bin\/bash  SERVER=\"user@example.com\" SESSION=\"remote_work\" SSH_OPTS=\"-o ServerAliveInterval=30 -o ServerAliveCountMax=3\"  while true; do     echo \"[$(date +'%H:%M:%S')] \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0441\u0435\u0441\u0441\u0438\u0438 $SESSION \u043d\u0430 $SERVER...\"     ssh -t $SSH_OPTS $SERVER \"tmux attach -t $SESSION || tmux new -s $SESSION\"          if [ $? -eq 0 ]; then         break     else         sleep 5     fi done<\/code><\/pre>\n<h4>PowerShell-\u0441\u043a\u0440\u0438\u043f\u0442<\/h4>\n<pre><code class=\"powershell\">$SERVER = \"user@example.com\" $SSH_OPTS = \"-o ServerAliveInterval=30 -o ServerAliveCountMax=3\" $DELAY = 5  while ($true) {     Write-Host \"[$(Get-Date -Format 'HH:mm:ss')] \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a $SERVER...\"     ssh $SSH_OPTS $SERVER          if ($LASTEXITCODE -eq 0) {         break     } else {         Start-Sleep -Seconds $DELAY     } }<\/code><\/pre>\n<h4>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h4>\n<ol>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"bash\">nano ssh_reconnect.sh chmod +x ssh_reconnect.sh<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c:<\/p>\n<pre><code class=\"bash\">.\/ssh_reconnect.sh &gt;&gt; ssh_log.txt 2&gt;&amp;1<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435:<\/p>\n<pre><code class=\"bash\">nohup .\/ssh_reconnect.sh &gt; \/dev\/null 2&gt;&amp;1 &amp;<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>\u0422\u0430\u043a\u0436\u0435, \u0435\u0449\u0451 \u043f\u0430\u0440\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/strong><\/p>\n<ol>\n<li>\n<p>Telegram-\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">TELEGRAM_API=\"https:\/\/api.telegram.org\/bot{TOKEN}\/sendMessage\" CHAT_ID=\"12345\" MESSAGE=\"\u041e\u0448\u0438\u0431\u043a\u0430 SSH \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 $SERVER\"  curl -s -X POST $TELEGRAM_API -d chat_id=$CHAT_ID -d text=\"$MESSAGE\"<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0410\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a \u0447\u0435\u0440\u0435\u0437 crontab:<\/p>\n<pre><code class=\"bash\">@reboot \/path\/to\/ssh_reconnect.sh<\/code><\/pre>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<pre><code class=\"bash\">ssh $SERVER \"cat &gt;&gt; ~\/.persistent_history\"<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438<\/h4>\n<ol>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 tmux \u0438\u043b\u0438 screen<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f ServerAliveInterval \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f terminal multiplexers<\/p>\n<\/li>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u0438\u0447\u0438\u043d \u0440\u0430\u0437\u0440\u044b\u0432\u043e\u0432<\/p>\n<\/li>\n<\/ol>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u044b\u0432\u043e\u0432 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<p><em>P.S. \u042f \u0432\u0435\u0434\u0443 \u0441\u0432\u043e\u044e \u0433\u0440\u0443\u043f\u043f\u0443 \u0432<\/em>\u00a0<a href=\"https:\/\/t.me\/automate_today\" rel=\"noopener noreferrer nofollow\"><em>\u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c<\/em><\/a><em>, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435\u0445, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u043c\u0438\u0440\u0435 IT.<\/em>  <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/927234\/\"> https:\/\/habr.com\/ru\/articles\/927234\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-467565","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467565"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467565\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}