How To Connect To Private IPFS Swarm

By Rishi Panthee

Connecting to a private IPFS swarm isn't too hard. You do need two things though, the swarm key and a boostrap node. Generally you should get these from wherever you need to connect to a private swarm from. Once you have those, you are ready to get started.

First thing to do is navitage to your ipfs's config directlroy. On most systems, it's located in a .ipfs directory which is located in your home directory. You can navigate to there using:

cd
cd .ipfs

If it is located elsewhere, just navigate to that specific folder. Next you'll want to create a swarm.key file. This will hold the private key for our swarm.

touch swarm.key

The key should look something like the following(not that is not a live key).

/key/swarm/psk/1.0.0/
/base16/
11111111111111111111111111111111111111111

Use you text editor of choice and save it into the swarm.key file. I like nano.

nano swarm.key

With nano I can paste using Command+V on mac + termius. Use what works with your tools to paste. Then I can save using Control + O, Control + X.


Now we need the boostrap node. If our booststrap node's was /ip6/2001:db8::1/tcp/4001/p2p/12D3KooWA8HDYEvVAZvVBzGS1gy6UMPaB7iDCRiofwTuAm78rbxe we'd use something like the following:

ipfs bootstrap add /ip6/2001:db8::1/tcp/4001/p2p/12D3KooWA8HDYEvVAZvVBzGS1gy6UMPaB7iDCRiofwTuAm78rbxe

You can do this multiple times if you have more than 1 boostrap node. More is better in this situation.


Then all we have to do is start up the IPFS node. I generally do this using pm2. For me its as simple as running the following:

pm2 start "ipfs daemon" --name ipfs

Then give it a few seconds to see if it was able to connect to the boostrap node. If you are able to, then you are all good and connected.