The Pi is installed now what do we do?
Make user accounts, file permissions, install a webserver
Users & Groups
Making a new user on the Pi
sudo adduser USERNAME
Add this user to the sudo group
sudo addgroup USERNAME GROUPNAME
sudo addgroup USERNAME sudo
Logout of the current ssh connection
exit
Now log in with your new user
ssh user@ipadress
Try to see if your sudo powers work
sudo test
Let's remove the user "pi".
It's not safe to keep the default user and password logins enabled.
Note! This means that you can only login with the useraccount you just made, so don't loose your password!
sudo deluser pi
If it does not work, it could be that the user pi is still being used. Try to reboot the pi and do it again.
sudo reboot ssh USERNAME@ip-adress sudo deluser pi
Change the hostname of the Pi
You can change this name, by editing these two files:
sudo nano /etc/hostname sudo nano /etc/hosts
Change /etc/hosts into:
127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.1.1 newhostname (needs to be the same as your hostname)
The hostname will be changed after a reboot.
So reboot and ssh in again.
sudo reboot ssh USERNAME@ip-address
or
ssh USERNAME@HOSTNAME.local (doesn't seem to work in the studio unfortunately, but at home this might work)
Install a webserver
So we can host webpages on our Pi, that can be reached when we type the ip-address in the browser.
sudo apt install nginx
Once it's done, let's go to the folder that nginx uses to serve files from:
cd /var/www/html/
And try to check if nginx serves you a file in the browser, by visiting the ip address of your pi:
145.24.131.184
To edit this page, remove the standard index file and make a new index.html file
sudo nano /var/www/html/index.html
You might get a permission denied error now.....
This is because the /var/www/html/ is not configured with the right permissions.
Let's make a group for all the users on this pi,
we will give this group the permissions to write in this folder.
sudo addgroup USERNAME users
File Permissions
Let's take a look at file permissions How do you know the permission settings of a file? And how do you change them?
(This is documented here too: https://pzwiki.wdka.nl/mediadesign/Shell_Cheat_Sheet#File_Permissions )
ls -la
Outputs:
total 24 drwxr-xr-x 3 flo flo 4096 Mar 4 16:03 . drwxr-xr-x 6 root root 4096 Mar 4 15:41 .. -rw-r--r-- 1 flo flo 220 Mar 4 15:41 .bash_logout -rw-r--r-- 1 flo flo 3523 Mar 4 15:41 .bashrc drwx------ 3 flo flo 4096 Mar 4 16:03 .gnupg -rw-r--r-- 1 flo flo 807 Mar 4 15:41 .profile
Let's unpack this!
d = directory
rwx rwx rwx U G O
u = user g = group o = others
Two programs can be used to change ownership and permissions:
chown = change ownership chmod = change mode (?)
To see the permissions of the /var/www/html folder
ls -l /var/www/
Outputs:
total 12 drwxr-xr-x 3 root root 4096 Mar 4 15:57 . drwxr-xr-x 12 root root 4096 Mar 4 15:57 .. drwxr-xr-x 2 root root 4096 Mar 4 15:58 html
Let's unpack this again!
d rwx r-x r-x U G O
owned by user: root owned by group: root
We want to change the permissions and ownership to:
user: root (or anything else) group: users G = rwx
To change ownership to user=root and group=users:
chown -R root:users /var/www/html/
To change the write permissions to the group:
chmod -R g+w /var/www/html/
Check if it worked:
ls -l
And try to edit the index.html file now in /var/www/html/
nano /var/www/html/index.html