secure python chat with ssh - how?

  • Last Update :
  • Techknowledgy :

Last Updated : 19 Feb, 2022

This server can be set up on a local area network by choosing any on the computer to be a server node, and using that computer’s private IP address as the server IP address. 
For example, if a local area network has a set of private IP addresses assigned ranging from 192.168.1.2 to 192.168.1.100, then any computer from these 99 nodes can act as a server, and the remaining nodes may connect to the server node by using the server’s private IP address. Care must be taken to choose a port that is currently not in usage. For example, port 22 is the default for ssh, and port 80 is the default for HTTP protocols. So these two ports preferably, shouldn’t be used or reconfigured to make them free for usage. 
However, if the server is meant to be accessible beyond a local network, the public IP address would be required for usage. This would require port forwarding in cases where a node from a local network (node that isn’t the router) wishes to host the server. In this case, we would require any requests that come to the public IP addresses to be re-routed towards our private IP address in our local network, and would hence require port forwarding. 
For more reading on port forwarding: link
To run the script, simply download it from the GitHub link specified at the bottom of the post, and save it at a convenient location on your computer. 

/* Both the server and client script can then be run
   from the Command prompt (in Windows) or from bash 
   Terminal (Linux users) by simply typing 
   "python chat_server.py  " or "python client.py  ". 
   For example, */
python chat_server.py 192.168 .55 .13 8081
python client.py 192.168 .55 .13 8081

Suggestion : 2

Tim June 12, 2017 at 7:49 pm Thanks! Reply

Start by downloading the latest version of ssh-chat from its release page and extract the tar file and move into the package directory to run it as shown.

# cd Downloads
# wget - c https: //github.com/shazow/ssh-chat/releases/download/v1.6/ssh-chat-linux_amd64.tgz
   # tar - xvf ssh - chat - linux_amd64.tgz
# cd ssh - chat /
   #. / ssh - chat

Important: You’ll notice that all the three users are not entering any passwords while connecting to the server, this is because we have setup passwordless login for ssh connections. This is the recommended method of authentication for ssh connections in Linux.

$ ssh[email protected]
$ ssh[email protected]
$ ssh[email protected]

While connected to the server over ssh, all the above system users can join the chat room using ssh command like this (they must use the port which the chat server is listening on):

$ ssh localhost - p 2022

To send a private message, for instance; if user tecmint wants to send a secret message to aaronkilik, he/she would need to use the /msg command as follows.

[tecmint] / msg aaronkilik Am a hacker btw![aaronkilik] / msg tecmint Oh, that 's cool

To view a users information, use the /whois command like this.

[aaronkilik] / whois tecmint

Suggestion : 3

SSH or Secure Socket Shell, is a network protocol that provides a secure way to access a remote computer. Secure Shell provides strong authentication and secure encrypted data communications between two computers connecting over an insecure network such as the Internet. SSH is widely used by network administrators for managing systems and applications remotely, allowing them to log in to another computer over a network, execute commands and move files from one computer to another.,In the below example we connect to a host and issue the command to identify the host type. We capture the result in and display it as a formatted text.,In python SSH is implemented by using the python library called fabric. It can be used to issue commands remotely over SSH. ,We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy. Agree Learn more

In the below example we connect to a host and issue the command to identify the host type. We capture the result in and display it as a formatted text.

from fabric
import Connection
result = Connection('xyz.com').run('uname -s')
msg = "Ran {.command!r} on {.connection.host}, got stdout:\n{.stdout}"
print(msg.format(result))

When we run the above program, we get the following output −

Linux

Suggestion : 4

The easiest way to install paramiko is using pip.

python - m pip install paramiko

To install from source, clone from GitHub and then install using setup.py.

git clone https: //github.com/paramiko/paramiko
   cd paramiko
python setup.py install

Connect to an SSH server using paramiko.client.SSHClient.connect(). The hostname is the only required parameter.

connect(hostname, port = 22, username = None, password = None, pkey = None, key_filename = None, timeout = None, allow_agent = True, look_for_keys = True, compress = False, sock = None, gss_auth = False, gss_kex = False, gss_deleg_creds = True, gss_host = None, banner_timeout = None, auth_timeout = None, gss_trust_dns = True, passphrase = None, disabled_algorithms = None)

You can also omit the key file and let Paramiko try to find the right key automatically in your ~/.ssh/ directory. You can turn that on by calling client.look_for_keys(True). The first example will show how to explicitly provide the key and passphrase and the second one will show how to look for keys.

# Explicitly provide key and passphrase
from paramiko
import SSHClient, AutoAddPolicy

client = SSHClient()
#client.load_system_host_keys()
#client.load_host_keys('~/.ssh/known_hosts')
#client.set_missing_host_key_policy(AutoAddPolicy())

client.connect('example.com', username = 'user', key_filename = 'mykey.pem', passphrase = 'mysshkeypassphrase')
client.close()

This example show hows to look for keys in ~/.ssh/ automatically.

from paramiko
import SSHClient

client = SSHClient()
#client.load_system_host_keys()
#client.load_host_keys('~/.ssh/known_hosts')
#client.set_missing_host_key_policy(AutoAddPolicy())

client.look_for_keys(True)
client.connect('example.com', username = 'user')
client.close()

Suggestion : 5

ShuSHH is a simple chat server that runs over SSH.,If you are not running in ephemeral mode (-e) the server will generate an RSA key file in the current directory. Keep this file safe! It is what verifies the authenticity of your host.,docopt (http://docopt.org/), docopt (http://docopt.org/)

# > python3 shusshd.py
Starting ShuSSH Daemon...
   Generating host key...
   Saving generated key as shusshd - rsa.key
Host fingerprint: 35: d8: 00: c0: 73: fc: 8 f: 32: db: 05: b7: 0 c: 7 e: a2: b2: 31
Listening
for connections on port 22...
$ > python3 shusshd.py - p 1024
Starting ShuSSH Daemon...
$ > ssh localhost
The authenticity of host 'localhost (127.0.0.1)'
can 't be established.
RSA key fingerprint is 35: d8: 00: c0: 73: fc: 8 f: 32: db: 05: b7: 0 c: 7 e: a2: b2: 31.
Are you sure you want to
continue connecting(yes / no) ?
Are you sure you want to
continue connecting(yes / no) ? yes
Warning: Permanently added 'localhost'(RSA) to the list of known hosts.
foo @localhost 's password: test
Permission denied, please
try again.
foo @localhost 's password: test
ShuSSH Server v0 .1
Welcome foo!
   Type / help
for a list of commands. >