Install mega-cmd from official website https://mega.io/cmd#download. For Raspberry Pi use Linux > Raspbian.
To create background service:
# Create the service file (copy content)
# WARNING: UPDATE LINE 7 "User=root" if you want to run it as different user
sudo nano /etc/systemd/system/mega.service
# Set proper permissions