Guide for setting up Rasbian lite running MotionEye headless for the Raspberry Pi 4
While reading the guide, replace all instances of <T3xtT0R3pl4ce>
(including the <
and >
symbols) with the appropriate value for your usage
It's highly recommended that you setup https with DDNS (afraid org) + Lets Encrypt (certbot) if you would like to access the web client remotely.
If you would like to boot off a USB, HDD, or SSD, follow this guide (use [gnu] dd rescue to clone the sdcard) then use fdisk
delete + new (make sure to start new partition on same sector as before) then e2fsck
and fsresize
, all while being on the sdcard, then reboot.
-
Download and install PuTTY
-
Download and install Rufus
-
Download Raspbian lite
-
Plug in a micro SD card of at least 4GB
-
Run Rufus, select the Raspbian Lite image, select the micro SD card, and click start
-
Open a file explorer and navigate to the micro SD card (if micro SD card doesn't show, see Troubleshooting 1)
-
Open
config.txt
in an editor and add the following lines to the end of the file:# Use gpu_mem=128 if a camera is attached to the device boot_delay=0 disable_splash=1 gpu_freq_min=250 arm_freq=1600 h264_freq=600
-
If using ssh, create a new file named
ssh
in the micro SD card's root directory and put a single space in it -
If using wifi, create another new file named
wpa_supplicant.conf
and set it's contents to:country=<iso alpha-2 code> ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ scan_ssid=1 ssid="<network name>" psk="<network password>" }
Valid
ISO Alpha 2
codes examples:US
DE
GB
CA
-
Eject the micro SD card from the computer
-
Insert the micro SD card into the Raspberry Pi
-
Plug in the Ethernet cable if available and power on the Raspberry Pi
-
Run PuTTY
-
Enter hostname
raspberrypi
and click "Open" (if PuTTY raises error "Host does not exist", see Troubleshooting 2) -
Login to the shell with login
pi
and passwordraspberry
-
Change root password with
sudo passwd root
the enter the new root password -
Create a new user
sudo adduser alice
-
Add user to sudo group
sudo usermod -aG sudo [new user name]
-
Switch to new user
sudo su - [new user name]
-
Stop user "pi" processes
sudo pkill -u pi
-
Delete the "pi" user
sudo deluser -remove-home pi
-
Set a static IP by running
sudo nano /etc/dhcpcd.conf
and adding the following lines (can be skiped with static dhcp on your router):interface wlan0 static ip_address=<static ip> static routers=<gateway ip> interface eth0 static ip_address=<static ip> static routers=<gateway ip>
Press
Ctrl + O
thenCtrl + X
to save and exit -
Update and upgrade software and firmware by running the following commands then reboot:
sudo apt update sudo apt full-upgrade sudo rpi-update sudo apt autoremove --purge sudo apt clean sudo reboot
-
Reconnect to the Raspberry Pi with PuTTY
-
Run
sudo raspi-config
then runUpdate
then change network hostname and localization options -
Reboot and reconnect to the Raspberry Pi with PuTTY using the new hostname/IP address
-
Setup fail2ban for added security
Run the following commands
sudo apt install python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev libavcodec58 libavdevice58 libavformat58 libavutil56 libmariadb3 libmicrohttpd12 libpq5 libswscale5 libwebp6 libwebpmux3 ffmpeg
mkdir -p ~/Downloads ; cd ~/Downloads
wget https://github.com/Motion-Project/motion/releases/download/release-4.2.2/pi_buster_motion_4.2.2-1_armhf.deb
sudo dpkg -i pi_buster_motion*
sudo pip install motioneye
Run the following commands
sudo mkdir -p /etc/motioneye /var/lib/motioneye
sudo cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf
sudo cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service
sudo systemctl daemon-reload
sudo systemctl enable motioneye
sudo systemctl start motioneye
Access MotionEye by going into your browser and going to <hostname>:8765
or <raspberry pi ip>:8765
. The default login is admin
with no password
Configure MotionEye to your liking using sudo nano /etc/motioneye/motioneye.conf
Periodically upgrade MotionEye using with the following commands:
sudo pip install -U motioneye
sudo systemctl restart motioneye
-
Acquire a [sub]domain via https://freedns.afraid.org/ (free) or some other domain / DNS service and point it to your IP (DDNS is recommended instead)
-
Run the following commands
sudo apt install nginx certbot python-certbot-nginx
sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
sudo nano /etc/nginx/conf.d/<my.d0m41n.0rg>.conf
- Insert the following lines
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name <my.d0m41n.0rg>;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8765/;
}
}
-
Portforward 80 to 80 on your [sub]domain aquired in step 5.1
-
Run the follow commands
sudo systemctl enable nginx
sudo systemctl start nginx
sudo certbot --nginx
-
Disable portforward for port 80 to 80, and enable it for port 443 to 443
-
See auth setup here
- https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
- https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
- This should result in a NginX config like the following:
server {
server_name nvr4.us.to;
auth_basic "restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8080/;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/nvr4.us.to/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/nvr4.us.to/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = nvr4.us.to) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name nvr4.us.to;
return 404; # managed by Certbot
}
- Press
Win
+R
- Type
diskpart
then pressEnter
then runlist disk
- Select the appropriate disk with
select disk <x>
where<x>
is the disk number - Run
list partition
- Select the appropriate partition with
select partition <y>
where<y>
is the partition number (usually partition 1, ~256MB) - Run
assign letter=i
- Check for drive
I
in your file explorer
- Check router (or use NMap) to get IP address of the Raspberry Pi (sort by access time if needed)
- Connect to the Raspberry Pi with PuTTY using the IP address