Implementing an SSH server with paramiko
In the following example, we are going to use the paramiko
library to implement our own SSH server by encrypting traffic with the SSH protocol. You can find the following code in the SSH_Server.py
file inside the paramiko
folder.
First, we review the code for the SSH server:
import socket, paramiko, threading, sys
import getpass
if len(sys.argv) != 3:
print("usage SSH_Server.py <interface> <port>")
exit()
class SSH_Server (paramiko.ServerInterface):
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 == 'linux') and (password == 'linux'):
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
The paramiko
package provides a class...