Question

SSH connect two droplets and can I access files in python script?

I posted my question about SSH networking here: https://www.digitalocean.com/community/tutorials/how-to-copy-files-with-rsync-over-ssh?comment=58880

I will repeat it: I have access from my pc to both of my droplets with ssh and putty. At my pc I have the public and the private (.ppk) ssh keys. This works fine.

Now I want both droplets to rsync in private network. I assueme I can still use the public and private keys I also use on pc in putty. But where do I put public and private key, so the first droplet knows that he can use this ssh keys to connect to droplet2 ?

  1. After transferring files with SSH is possible, if want a python 3 script that is running at one of them, to be able to read txt files from the other droplet. Does anyone has a clue how to do that?
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@scholastik

The purpose of rysnc would be to ensure that the specified files and directories on Droplet A are in sync with Droplet B and vice versa. If that’s the case, you should be able to simply read the file on the server that you’re running the Python script on without having to go over the network to do it.

As a very basic example, if we have a file called demo.txt and it exists on Droplet A, and you’re using rsync to duplicate that file over to Droplet B, then you should be able to read that file on either using a Python script without having to go over the network.

Any changes you make on either Droplet A or Droplet B could then be synced using rysnc.

If you need to connect over SSH from your Python script, I’d take a look at the following. There are a few demo scripts that you can use to get things setup.

https://github.com/paramiko/paramiko