{"id":367403,"date":"2024-05-21T03:20:17","date_gmt":"2024-05-21T03:20:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=367403"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T03:20:17","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=367403","title":{"rendered":"<span>\u041f\u043e\u0434\u0434\u0435\u043b\u043a\u0430 ssh \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Python<\/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<h2>\u0421\u043f\u043e\u0439\u043b\u0435\u0440\u044b<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0438\u0433\u0440\u0430\u043b\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u043d\u0430 python \u0441\u043e\u043a\u0435\u0442\u044b, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 ssh \u043a\u043b\u0438\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 (\u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0440\u044b\u043c\u0438 \u043b\u044e\u0434\u044c\u043c\u0438) \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<pre><code>ssh root@ssh.vsecoder.dev -p 2200<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/acd\/9b1\/80d\/acd9b180d85f8d064b401c446a9f2c27.png\" alt=\"\u043f\u0430\u0440\u043e\u043b\u044c habr\" title=\"\u043f\u0430\u0440\u043e\u043b\u044c habr\" width=\"504\" height=\"226\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/acd\/9b1\/80d\/acd9b180d85f8d064b401c446a9f2c27.png\"\/><\/p>\n<div><figcaption>\u043f\u0430\u0440\u043e\u043b\u044c habr<\/figcaption><\/div>\n<\/figure>\n<p>\u042d\u0442\u043e \u0441\u0442\u0435\u043d\u0430 &#171;\u0411\u044b\u043b \u0437\u0434\u0435\u0441\u044c&#187;, \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0438\u043a, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442, \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0434\u0440\u0443\u0433\u0438\u043c.<\/p>\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ssh \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e\u0434\u0438\u043d \u0430\u0432\u0442\u043e\u0440 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435: <a href=\"https:\/\/habr.com\/ru\/articles\/122445\/\" rel=\"noopener noreferrer nofollow\"><u>\u041f\u0430\u043c\u044f\u0442\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c ssh<\/u><\/a>.<\/p>\n<p>\u042f \u043b\u0438\u0448\u044c \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0441\u0445\u0435\u043c\u043a\u0443 \u043e\u0442 \u0440\u0435\u0433.\u0440\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5b9\/b99\/866\/5b9b998665a8841e47732cbb25388fac.png\" alt=\"\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b ssh\" title=\"\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b ssh\" width=\"904\" height=\"363\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5b9\/b99\/866\/5b9b998665a8841e47732cbb25388fac.png\"\/><\/p>\n<div><figcaption>\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b ssh<\/figcaption><\/div>\n<\/figure>\n<p>\u0418 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043c SSH-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u0432\u043e\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043d\u0430 Python, \u0430 \u0437\u0430 tcp \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c socket.<\/p>\n<h2>\u041d\u0430\u0447\u043d\u0451\u043c<\/h2>\n<p><code>Socket<\/code> &#8212; \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u041e\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u043e\u043a\u0435\u0442\u0430\u00a0<code>Socket<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043d\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 IP \u0430\u0434\u0440\u0435\u0441 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e \u0441\u0435\u0442\u0438.  <\/p>\n<p>\u0421\u043e\u043a\u0435\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u043e\u0438\u0445 \u043a\u043e\u043d\u0446\u043e\u0432 \u0441\u043e\u043a\u0435\u0442\u0430 TCP\/IP \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c.  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<p><a href=\"https:\/\/docs-python.ru\/standart-library\/modul-socket-setevoj-interfejs-python\/\" rel=\"noopener noreferrer nofollow\"><em><u>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440<\/u><\/em><\/a><\/p>\n<pre><code class=\"python\"># \u0441\u0435\u0440\u0432\u0435\u0440 import socket import sys  # \u0441\u043e\u0437\u0434\u0430\u0435\u043c TCP\/IP \u0441\u043e\u043a\u0435\u0442 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # \u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u043a\u0435\u0442 \u043a \u043f\u043e\u0440\u0442\u0443 server_address = ('localhost', 1234) sock.bind(server_address)  # \u0421\u043b\u0443\u0448\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f sock.listen(1)  while True:     # \u0436\u0434\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f     connection, client_address = sock.accept()     try:         # \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 \u0438 \u0440\u0435\u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u043c \u0438\u0445         while True:             data = connection.recv(16)             if data:                 data = data.upper()                 print(data)                 connection.sendall(data)             else:                 break      finally:         # \u041e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435         connection.close()<\/code><\/pre>\n<pre><code class=\"python\"># \u043a\u043b\u0438\u0435\u043d\u0442 import socket import sys  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c TCP\/IP \u0441\u043e\u043a\u0435\u0442 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u043e\u043a\u0435\u0442 \u043a \u043f\u043e\u0440\u0442\u0443, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440 server_address = ('localhost', 10000) print('\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043a {} \u043f\u043e\u0440\u0442 {}'.format(*server_address)) sock.connect(server_address)  try:     # \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445     mess = 'Hello W\u043erld!'     print(f'\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430: {mess}')     message = mess.encode()     sock.sendall(message)          # \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0442\u0432\u0435\u0442     amount_received = 0     amount_expected = len(message)     while amount_received &lt; amount_expected:         data = sock.recv(16)         amount_received += len(data)         mess = data.decode()         print(f'\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e: {data.decode()}')  finally:     sock.close()<\/code><\/pre>\n<p>\u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0441\u043e\u043a\u0435\u0442, \u0442.\u043a. \u0432 \u0440\u043e\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 ssh \u043a\u043b\u0438\u0435\u043d\u0442.<\/p>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0451 \u043b\u0435\u0433\u043a\u043e, \u043f\u043e\u0434\u043d\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442, \u0434\u0430 \u043e\u0431\u0449\u0430\u0439\u0441\u044f, \u043d\u043e \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u043a\u0435\u0442 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0df\/654\/57e\/0df65457e6fff9343401438bfeaa866f.png\" alt=\"\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 ssh\" title=\"\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 ssh\" width=\"1683\" height=\"226\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0df\/654\/57e\/0df65457e6fff9343401438bfeaa866f.png\"\/><\/p>\n<div><figcaption>\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 ssh<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0447\u0435\u0442 \u0441 \u043d\u0430\u043c\u0438 \u043f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f, \u0438 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0430\u0442\u044c \u0435\u043c\u0443 \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0440\u0432\u0451\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>Connection reset by 127.0.0.1 port 1234<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0440\u0443\u0447\u043a\u0430\u043c\u0438, \u043d\u043e \u044f \u043d\u0430\u0448\u0451\u043b \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0439 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 &#8212; <code>paramiko<\/code>.<\/p>\n<p>\u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c ssh \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u0443 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0442\u0430\u043a \u0438 <a href=\"https:\/\/github.com\/paramiko\/paramiko\/blob\/main\/demos\/demo_server.py\" rel=\"noopener noreferrer nofollow\">\u043e\u0434\u0438\u043d \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/a>, \u043d\u043e \u043c\u043d\u0435 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430\u0436\u0443 \u0441\u0432\u043e\u0439:<\/p>\n<pre><code class=\"python\">import socket import paramiko import threading from paramiko import Transport, RSAKey  # ssh-keygen good_pub_key = RSAKey(filename=\"test.rsa\")   class Server(paramiko.ServerInterface):     def __init__(self):         self.event = threading.Event()         self.user = 'root'         self.password = 'root'      def check_channel_request(self, kind, chanid):         if kind == \"session\":             return paramiko.OPEN_SUCCEEDED         return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED      def check_auth_password(self, username, password):         if (username == self.user) and (password == self.password):             return paramiko.AUTH_SUCCESSFUL         return paramiko.AUTH_FAILED      def check_auth_publickey(self, username, key):         if (username == self.user) and (key == good_pub_key):             return paramiko.AUTH_SUCCESSFUL         return paramiko.AUTH_FAILED      def enable_auth_gssapi(self):         return False      def get_allowed_auths(self, username):         return \"password,publickey\"      def check_channel_shell_request(self, channel):         self.event.set()         return True      def check_channel_pty_request(         self, channel, term, width, height, pixelwidth, pixelheight, modes     ):         return True   if __name__ == \"__main__\":     server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)     server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)     server.bind(('', 2200))     server.listen(5)      while True:         try:             client, addr = server.accept()              t = Transport(client)             t.load_server_moduli()             t.add_server_key(good_pub_key)             t.start_server(server=Server())              chan = t.accept(20)              if not chan:                 continue              chan.send(                 \"Welcome to my test server!\\n \\r\"             )              chan.send(\"\\n \\n \\r\")              chan.close()         except Exception as e:             print(e) <\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 (\u043a\u043b\u0430\u0441\u0441 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0435 \u211610), \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438 \u0442\u0434.<\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 ssh-keygen \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 7\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043f\u0443\u0442\u044c \u043a \u043d\u0435\u043c\u0443. \u0412\u043e\u0442 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443:<\/p>\n<pre><code>> ssh root@localhost -p 2200 root@localhost's password: Permission denied, please try again. root@localhost's password:  Welcome to my test server!  Connection to localhost closed.<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c, \u0442\u0430\u043a \u0436\u0435 paramiko \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0435 \u043a\u043b\u044e\u0447\u0438, \u0438, \u0432\u0440\u043e\u0434\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043d\u043e \u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435 \u043d\u0430\u0448\u0451\u043b.<\/p>\n<h2>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435? <\/h2>\n<p><strong>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u043d\u043e:<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043a\u0430\u043b\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0440\u0435\u0430\u043a\u0446\u0438\u044e, \u0435\u0441\u043b\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 (\u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0449\u0438\u0442\u0435, \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u0442 ssh, \u0430 \u0441\u043e\u043a\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0430 22\u043c \u043f\u043e\u0440\u0442\u0435):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d53\/bc3\/320\/d53bc3320db179cb7fec227b839cb4b3.png\" width=\"629\" height=\"1033\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d53\/bc3\/320\/d53bc3320db179cb7fec227b839cb4b3.png\"\/><\/figure>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e ASCII \u0433\u0430\u043b\u0435\u0440\u0435\u044e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/624\/0b5\/50e\/6240b550eb88f667d4ffa6dfd7327c24.png\" width=\"1114\" height=\"951\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/624\/0b5\/50e\/6240b550eb88f667d4ffa6dfd7327c24.png\"\/><\/figure>\n<\/li>\n<li>\n<p>\u0414\u0430 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u043e\u0432, tcp \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u0442\u0434.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430:<\/h3>\n<ol>\n<li>\n<p><a href=\"https:\/\/docs-python.ru\/standart-library\/modul-socket-setevoj-interfejs-python\/\" rel=\"noopener noreferrer nofollow\">https:\/\/docs-python.ru\/standart-library\/modul-socket-setevoj-interfejs-python\/<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/help.reg.ru\/support\/hosting\/dostupy-i-podklyucheniye-panel-upravleniya-ftp-ssh\/chto-takoye-ssh\" rel=\"noopener noreferrer nofollow\">https:\/\/help.reg.ru\/support\/hosting\/dostupy-i-podklyucheniye-panel-upravleniya-ftp-ssh\/chto-takoye-ssh<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.paramiko.org\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.paramiko.org<\/a><\/p>\n<\/li>\n<\/ol>\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\/791620\/\"> https:\/\/habr.com\/ru\/articles\/791620\/<\/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<h2>\u0421\u043f\u043e\u0439\u043b\u0435\u0440\u044b<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0438\u0433\u0440\u0430\u043b\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u043d\u0430 python \u0441\u043e\u043a\u0435\u0442\u044b, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 ssh \u043a\u043b\u0438\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 (\u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0440\u044b\u043c\u0438 \u043b\u044e\u0434\u044c\u043c\u0438) \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<pre><code>ssh root@ssh.vsecoder.dev -p 2200<\/code><\/pre>\n<figure class=\"\">\n<div><figcaption>\u043f\u0430\u0440\u043e\u043b\u044c habr<\/figcaption><\/div>\n<\/figure>\n<p>\u042d\u0442\u043e \u0441\u0442\u0435\u043d\u0430 &#171;\u0411\u044b\u043b \u0437\u0434\u0435\u0441\u044c&#187;, \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0438\u043a, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442, \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0434\u0440\u0443\u0433\u0438\u043c.<\/p>\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ssh \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e\u0434\u0438\u043d \u0430\u0432\u0442\u043e\u0440 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435: <a href=\"https:\/\/habr.com\/ru\/articles\/122445\/\" rel=\"noopener noreferrer nofollow\"><u>\u041f\u0430\u043c\u044f\u0442\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c ssh<\/u><\/a>.<\/p>\n<p>\u042f \u043b\u0438\u0448\u044c \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0441\u0445\u0435\u043c\u043a\u0443 \u043e\u0442 \u0440\u0435\u0433.\u0440\u0443:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b ssh<\/figcaption><\/div>\n<\/figure>\n<p>\u0418 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043c SSH-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u0432\u043e\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043d\u0430 Python, \u0430 \u0437\u0430 tcp \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c socket.<\/p>\n<h2>\u041d\u0430\u0447\u043d\u0451\u043c<\/h2>\n<p><code>Socket<\/code> &#8212; \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u041e\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u043e\u043a\u0435\u0442\u0430\u00a0<code>Socket<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043d\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 IP \u0430\u0434\u0440\u0435\u0441 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e \u0441\u0435\u0442\u0438.  <\/p>\n<p>\u0421\u043e\u043a\u0435\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u043e\u0438\u0445 \u043a\u043e\u043d\u0446\u043e\u0432 \u0441\u043e\u043a\u0435\u0442\u0430 TCP\/IP \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c.  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<p><a href=\"https:\/\/docs-python.ru\/standart-library\/modul-socket-setevoj-interfejs-python\/\" rel=\"noopener noreferrer nofollow\"><em><u>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440<\/u><\/em><\/a><\/p>\n<pre><code class=\"python\"># \u0441\u0435\u0440\u0432\u0435\u0440 import socket import sys  # \u0441\u043e\u0437\u0434\u0430\u0435\u043c TCP\/IP \u0441\u043e\u043a\u0435\u0442 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # \u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u043a\u0435\u0442 \u043a \u043f\u043e\u0440\u0442\u0443 server_address = ('localhost', 1234) sock.bind(server_address)  # \u0421\u043b\u0443\u0448\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f sock.listen(1)  while True:     # \u0436\u0434\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f     connection, client_address = sock.accept()     try:         # \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 \u0438 \u0440\u0435\u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u043c \u0438\u0445         while True:             data = connection.recv(16)             if data:                 data = data.upper()                 print(data)                 connection.sendall(data)             else:                 break      finally:         # \u041e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435         connection.close()<\/code><\/pre>\n<pre><code class=\"python\"># \u043a\u043b\u0438\u0435\u043d\u0442 import socket import sys  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c TCP\/IP \u0441\u043e\u043a\u0435\u0442 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u043e\u043a\u0435\u0442 \u043a \u043f\u043e\u0440\u0442\u0443, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440 server_address = ('localhost', 10000) print('\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043a {} \u043f\u043e\u0440\u0442 {}'.format(*server_address)) sock.connect(server_address)  try:     # \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445     mess = 'Hello W\u043erld!'     print(f'\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430: {mess}')     message = mess.encode()     sock.sendall(message)          # \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0442\u0432\u0435\u0442     amount_received = 0     amount_expected = len(message)     while amount_received &lt; amount_expected:         data = sock.recv(16)         amount_received += len(data)         mess = data.decode()         print(f'\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e: {data.decode()}')  finally:     sock.close()<\/code><\/pre>\n<p>\u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0441\u043e\u043a\u0435\u0442, \u0442.\u043a. \u0432 \u0440\u043e\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 ssh \u043a\u043b\u0438\u0435\u043d\u0442.<\/p>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0451 \u043b\u0435\u0433\u043a\u043e, \u043f\u043e\u0434\u043d\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442, \u0434\u0430 \u043e\u0431\u0449\u0430\u0439\u0441\u044f, \u043d\u043e \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u043a\u0435\u0442 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 ssh<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0447\u0435\u0442 \u0441 \u043d\u0430\u043c\u0438 \u043f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f, \u0438 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0430\u0442\u044c \u0435\u043c\u0443 \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0440\u0432\u0451\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>Connection reset by 127.0.0.1 port 1234<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0440\u0443\u0447\u043a\u0430\u043c\u0438, \u043d\u043e \u044f \u043d\u0430\u0448\u0451\u043b \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0439 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 &#8212; <code>paramiko<\/code>.<\/p>\n<p>\u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c ssh \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u0443 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0442\u0430\u043a \u0438 <a href=\"https:\/\/github.com\/paramiko\/paramiko\/blob\/main\/demos\/demo_server.py\" rel=\"noopener noreferrer nofollow\">\u043e\u0434\u0438\u043d \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/a>, \u043d\u043e \u043c\u043d\u0435 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430\u0436\u0443 \u0441\u0432\u043e\u0439:<\/p>\n<pre><code class=\"python\">import socket import paramiko import threading from paramiko import Transport, RSAKey  # ssh-keygen good_pub_key = RSAKey(filename=\"test.rsa\")   class Server(paramiko.ServerInterface):     def __init__(self):         self.event = threading.Event()         self.user = 'root'         self.password = 'root'      def check_channel_request(self, kind, chanid):         if kind == \"session\":             return paramiko.OPEN_SUCCEEDED         return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED      def check_auth_password(self, username, password):         if (username == self.user) and (password == self.password):             return paramiko.AUTH_SUCCESSFUL         return paramiko.AUTH_FAILED      def check_auth_publickey(self, username, key):         if (username == self.user) and (key == good_pub_key):             return paramiko.AUTH_SUCCESSFUL         return paramiko.AUTH_FAILED      def enable_auth_gssapi(self):         return False      def get_allowed_auths(self, username):         return \"password,publickey\"      def check_channel_shell_request(self, channel):         self.event.set()         return True      def check_channel_pty_request(         self, channel, term, width, height, pixelwidth, pixelheight, modes     ):         return True   if __name__ == \"__main__\":     server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)     server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)     server.bind(('', 2200))     server.listen(5)      while True:         try:             client, addr = server.accept()              t = Transport(client)             t.load_server_moduli()             t.add_server_key(good_pub_key)             t.start_server(server=Server())              chan = t.accept(20)              if not chan:                 continue              chan.send(                 \"Welcome to my test server!\\n \\r\"             )              chan.send(\"\\n \\n \\r\")              chan.close()         except Exception as e:             print(e) <\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 (\u043a\u043b\u0430\u0441\u0441 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0435 \u211610), \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438 \u0442\u0434.<\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 ssh-keygen \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 7\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043f\u0443\u0442\u044c \u043a \u043d\u0435\u043c\u0443. \u0412\u043e\u0442 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443:<\/p>\n<pre><code>> ssh root@localhost -p 2200 root@localhost's password: Permission denied, please try again. root@localhost's password:  Welcome to my test server!  Connection to localhost closed.<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c, \u0442\u0430\u043a \u0436\u0435 paramiko \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0435 \u043a\u043b\u044e\u0447\u0438, \u0438, \u0432\u0440\u043e\u0434\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043d\u043e \u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435 \u043d\u0430\u0448\u0451\u043b.<\/p>\n<h2>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435? <\/h2>\n<p><strong>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u043d\u043e:<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043a\u0430\u043b\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0440\u0435\u0430\u043a\u0446\u0438\u044e, \u0435\u0441\u043b\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 (\u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0449\u0438\u0442\u0435, \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u0442 ssh, \u0430 \u0441\u043e\u043a\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0430 22\u043c \u043f\u043e\u0440\u0442\u0435):<\/p>\n<figure class=\"full-width\"><\/figure>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e ASCII \u0433\u0430\u043b\u0435\u0440\u0435\u044e:<\/p>\n<figure class=\"full-width\"><\/figure>\n<\/li>\n<li>\n<p>\u0414\u0430 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u043e\u0432, tcp \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u0442\u0434.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430:<\/h3>\n<ol>\n<li>\n<p><a href=\"https:\/\/docs-python.ru\/standart-library\/modul-socket-setevoj-interfejs-python\/\" rel=\"noopener noreferrer nofollow\">https:\/\/docs-python.ru\/standart-library\/modul-socket-setevoj-interfejs-python\/<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/help.reg.ru\/support\/hosting\/dostupy-i-podklyucheniye-panel-upravleniya-ftp-ssh\/chto-takoye-ssh\" rel=\"noopener noreferrer nofollow\">https:\/\/help.reg.ru\/support\/hosting\/dostupy-i-podklyucheniye-panel-upravleniya-ftp-ssh\/chto-takoye-ssh<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.paramiko.org\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.paramiko.org<\/a><\/p>\n<\/li>\n<\/ol>\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\/791620\/\"> https:\/\/habr.com\/ru\/articles\/791620\/<\/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-367403","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367403","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=367403"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367403\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}