Skip to content

Instantly share code, notes, and snippets.

@Zhiyuan-Amos
Last active May 2, 2022 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zhiyuan-Amos/6896f22b46cd5775387293a0dd8806b7 to your computer and use it in GitHub Desktop.
Save Zhiyuan-Amos/6896f22b46cd5775387293a0dd8806b7 to your computer and use it in GitHub Desktop.

Install Nextcloud on Raspberry Pi

Execute the following commands in a bash shell.

Install Nextcloud using snap

sudo apt update
sudo apt install snapd -y
sudo reboot
sudo snap install core
sudo snap install nextcloud

Access Nextcloud locally or remotely on http://{ip} with user admin and password admin.

Enable HTTPS

sudo /snap/bin/nextcloud.enable-https self-signed

This also redirects all HTTP traffic to HTTPS.

Use External Storage

Ensure that only the external storage to be used to store Nextcloud's data is the only external storage attached to the Raspberry Pi.

Mount External Storage

sudo mkdir /mnt/usb
sudo mount /dev/sda1 /mnt/usb -o uid=pi,gid=pi

Mount on Boot

Update fs to the external storage's file system. Consider running sudo fdisk -l to retrieve the value.

uuid=$(sudo ls -l /dev/disk/by-uuid/ | grep sda1 | awk '{print $9}')
echo "UUID=${uuid} /mnt/usb auto defaults,uid=pi,gid=pi,dmask=007,nofail,x-systemd.device-timeout=5 0 0" | sudo tee -a /etc/fstab

Configure Nextcloud to use External Storage

  1. Update the value of datadirectory in /var/snap/nextcloud/current/nextcloud/config/config.php to the new storage path in /mnt/usb/ e.g. /mnt/usb/data.
  2. Run the following code with the new storage path.
path=/mnt/usb/data
sudo snap disable nextcloud
sudo mv /var/snap/nextcloud/common/nextcloud/data "${path}"
sudo snap enable nextcloud

Set static IP

Warning: After running the commands in this section, the Raspberry Pi will not be able to access the Internet. To undo this operation, delete the appended configurations in /etc/dhcpcd.conf and run sudo reboot.

Initialize the following variables:

network={eth0|wlan0} // Ethernet or wireless respectively
ip={ip} // static IP address for the Raspberry Pi
routerIp={routerIp} // the gateway IP address for your router on the local network. Typically 192.168.0.1
dnsIp={dnsIp} // the DNS IP address (typically the same as your router’s gateway address)

E.g.

network=wlan0
ip=$(hostname -I)
routerIp=$(ip route | grep default | awk '{print $3}')
dnsIp="${routerIp}"

Then, run

lines=("interface ${network}" "static ip_address=${ip}/24" "static routers=${routerIp}" "static domain_name_servers=${dnsIp}")
for line in "${lines[@]}"; do echo $line | sudo tee -a /etc/dhcpcd.conf; done

Then, run sudo reboot.

Common Security Issues

  1. Disable SSH
  2. Create a separate User Account
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment