Back to blog

How to Run IPFS on a Raspberry Pi

How to Run IPFS on a Raspberry Pi

Steve

If you’re a developer or a tinkerer, then you probably have played with a Raspberry Pi at some point. They’re incredibly versatile mini-computers, capable of playing games, running a normal desktop, cybersecurity tools, and helping power a decentralized file-sharing network like IPFS. In order for these types of networks to truly grow and spread more people need to run their own IPFS nodes to help distribute content. There a lots of ways you can do this today, some of them easy as installing an app on your computer and letting it run. The only downside is that it can hog resources on your computer, create a heavy cache, and you likely won’t keep it on 24/7. This is where a Raspberry Pi is perfect, because you can plug it in, let it run all day, and you can access it from your computer without sacrificing your own performance. In this post, we’ll show you how to set up IPFS on a Raspberry Pi, as well as how to upload files to IPFS & Pinata from it!

To get started you will need a few things.

  • Raspberry Pi 3/4 - You can try some older models but make sure it has 64bit architecture.
  • Micro SD card and card reader - Can be any size but would recommend a 32GB minimum.
  • SSH  - If you have never set up SSH before on your computer it's pretty simple, would recommend following this guide.
  • Pinata Account - Want to back up your pins to Pinata? Sign up for a free account and then follow these steps to make an API key. Be sure to save the JWT that we’ll be using in this tutorial!

Raspberry Pi Setup

Getting the software installed on our Raspberry Pi won’t be too difficult thanks to their Raspberry Pi OS Imager which you can download here. This will allow us to burn an operating software to our micro SD card, which we’ll later boot into on the Raspberry Pi. When you install the imager and run it, you’ll see the first button to “Choose OS.” Go ahead and click on that.

Scroll down the list and select “Raspberry Pi OS (other).”

Then select “Raspberry Pi OS Lite (64-bit).” This is going to be a more minimal, terminal-only operating system which will take up less space and make our IPFS node more performant.

Once you select that it will take you to the main screen again where you can click “Choose Storage” where you will want to locate and select your Micro SD card that is plugged into your computer.

Now before we write this software, we need to preconfigure a few things. Since this is terminal only and we may not have an easy way to see what we’re typing, setting up stuff like wifi could be tricky. Thankfully the imager tool has some awesome tricks to make this simpler. On the main screen click the little setting cog.

You should see this next screen with a lot of stuff to fill out, but we’ll break down each bit to make it simple.

  • Set Hostname - For this, you can make it whatever name you want it to be! It will basically be the name of the computer. Could name it raspberrypi, ipfsnode, or in my case “kubo.”
  • Enable SSH - For this one, you will want to use “Allow public-key authentication only” and you will want to paste in your public ssh key where it says Set authorized_keys for steve. If you’re not sure how to do that you can check out this guide here.
  • Set username and password - This will be used for running certain code like sudo commands so be sure to set what you want your username to be and a password, just like any other computer.
  • Configure wireless LAN - Here you can manually type in the name of your wifi and the password for it. What’s great about this is that your Raspberry Pi will automatically to your home wifi and make it discoverable for SSH.
  • Set locale settings - Handy to make sure you’re in the right timezone and have the correct keyboard layout.

Thats it! Save those settings then hit “Write.” It should only take a minute or two, and once its done you can remove the micro SD card.

Now that our micro SD card has our preconfigured software, plug it into the Raspberry Pi and power it up with a USB-C cable, and give it a minute or so to boot up. The next step is a bit tricky because in order to ssh into our Pi, we need the IP address. This is assigned by your router when you connect to the wifi, so in order to get it you may need to use your home router to find the IP address. Another hack you can try is installing arp-scan in your terminal and then running sudo arp-scan -l. Doing so will list all the devices connected to that wifi and you should see the name Raspberry Pi somewhere with the IPV4 address.

Once you have the IP address, you can ssh into the Pi like so:

ssh [email protected]

Just keep in mind the IP I’m using here is just an example, it will likely be totally different for your Pi. Once you run this command it will prompt you to enter the passphrase for your ssh key if you have one, prompt if you want to leave a fingerprint to which you’ll want to type yes. Then you should be logged in!

Installing and Setting Up IPFS

To install IPFS we’re going to download Kubo, a Go implementation of an IPFS node. Visit the releases page of Kubo to select which version you want to use. If you’re using Raspberry Pi OS Lite 64-bit that we set up earlier, you’re gonna want to download kubo_v0.23.3_linux-arm64.tar.gz. The version might be more advanced depending on when you’re reading this post, but Linux should still be relevant, as well as the arm64 architecture. To download it you can run:

wget "https://github.com/ipfs/kubo/releases/download/v0.23.0/kubo_v0.23.0_linux-arm64.tar.gz"

If it downloads successfully you can extract the zip file with tar -xf followed by the file name.

tar -xf kubo_v0.23.0_linux-arm64.tar.gz

This should create a new folder called kubo, which you will want to cd into and run the install.sh script.

cd kubo && sudo ./install.sh

This will move the IPFS program from the folder to /usr/bin where it can be run. To make sure it was installed correctly run the following command to check the version.

ipfs --version

If you get the current version then the installation was a success! Now let’s set up the IPFS node to run non-stop, and turn it back on whenever we power it on. To do that you will want to run the following command.

sudo nano /etc/systemd/user/ipfs.service

This will create a new file using the nano text editor where we will paste in a config file into system, giving us the ability to have this run in the background. Once that file is open paste in the following.

[Unit]
Description=InterPlanetary File System (IPFS) daemon
Documentation=https://docs.ipfs.io/
After=network.target

[Service]
Type=notify
ExecStart=/usr/local/bin/ipfs daemon --enable-gc=true --migrate=true
ExecStop=/usr/local/bin/ipfs shutdown
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=default.target

Once you have that pasted in you will want to hit Ctrl + O to save the file, then Ctrl + x to exit the nano text editor. Now that we have that file in place, run the following commands in order.

ipfs init --profile=server --empty-repo
systemctl --user enable ipfs
systemctl --user start ipfs
systemctl --user status ipfs
loginctl enable-linger $USER

Let’s walk through these just so you know what's going on!

  • ipfs init --profile=server --empty-repo - This one is prepping our IPFS node to run and does so with some settings that will optimize it as a server node.
  • systemctl --user enable ipfs & systemctl --user start ipfs - With this command, we fire up the ipfs.service file we made earlier, creating a background daemon that will continue to run 24/7.
  • systemctl --user status ipfs - After you run this command you should see an output about what happened when the daemon was started, and it should show the logs from the IPFS node starting up!
  • loginctl enable-linger $USER - This command will make sure our daemon will continue to run even after we leave the ssh session.

That’s it! Your Raspberry Pi IPFS node is officially in business, and even if you turn it off or unplug it, you can just plug it back in and it will start up again. But let’s not stop there; what if you want to use it to upload files to IPFS and perhaps back them up to Pinata?

Uploading Files via Pinata Pinning Service API

Running an IPFS node is a good and noble deed for the sake of the decentralized network, however, if you want to actively use it to host files and share them with others, that’s when it can get a bit tricky. Since it’s just one IPFS node, it can make discovering any content you pin difficult. Thankfully the implementors of IPFS thought about this and saw the value of pinning services and created something called the Pinning Service API. This allows you to connect your IPFS node to a larger pinning service like Pinata to help expand the reach of your content, as it uploads pins from your node to your Pinata account where they are broadcasted on a large global network of IPFS nodes.

Setting up the link between your node and Pinata is pretty simple. First, you will need to get a Pinata account and API key, both of which are free! If you haven’t done that already, be sure to sign up here and learn how to make an API key here. We will want to use the JWT in particular so be sure to save that when you create the key. Something else you may need is a way to transfer the files from your local machine to the Raspberry Pi. There are a few ways to do this, an FTP client to move files is one of them. In any case, the best way to make them accessible is to put them in /home/yourname/ where your home directory is.

To set up the Pinata Pinning Service API just paste in this line, and be sure to replace PINATA_JWT with the API key JWT that you created earlier.

ipfs pin remote service add pinata https://api.pinata.cloud/psa PINATA_JWT

Then run this command to make sure it was successfully added.

ipfs pin remote service ls

If it worked then you should see Pinata listed! Now let’s upload a file. Run the command simply by using the name of your file instead. Make sure it's the correct path, so for instance if you have it in a folder called documents then it would be ./Documents/filename.ext

ipfs add filename.ext

So for example, if I had a file called pinnie.png in my home directory I would simply run ipfs add pinnie.png. Easy! It should respond with the CID after pinning is complete

Now we can add that file to Pinata with the following command.

ipfs pin remote add CID --service=pinata --background=true --name=myfile

In our case, we’ll paste in the CID we just got back for Pinnie, and we’ll give it the name of pinnie.png. If you have a larger file that will take some time, you can add --background=true to let the pinning command run in the background.

Nice!! Now our wonderful image of Pinnie is being distributed by not only my Raspberry Pi, but Pinata’s IPFS node network as well, making sure no one has issues seeing it.

There’s nothing more satisfying than knowing that at your home, office, or where your Raspberry Pi is plugged in, you’re taking part in growing the IPFS network and helping the distribution of content all over the world. Who knows what could be floating through your node; it could be the latest and greatest NFT image, it could be an important journalism document, or it could even be a website! Now you can upload to IPFS too, and back up any content to a pinning service like Pinata.

Happy Pinning!

Subscribe to paid plan image

Share this post:

Stay up to date

Join our newsletter for the latest stories & product updates from the Pinata community.