The Pi is installed now what do we do?: Difference between revisions
(Created page with "=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 s...") |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
Making a new user on the Pi | Making a new user on the Pi | ||
sudo adduser USERNAME | |||
Add this user to the sudo group | Add this user to the sudo group | ||
sudo addgroup USERNAME GROUPNAME | |||
sudo addgroup USERNAME sudo | |||
Logout of the current ssh connection | Logout of the current ssh connection | ||
exit | |||
Now log in with your new user | Now log in with your new user | ||
ssh user@ipadress | |||
Try to see if your sudo powers work | Try to see if your sudo powers work | ||
sudo test | |||
Let's remove the user "pi". <br> | Let's remove the user "pi". <br> | ||
It's not safe to keep the default user and password logins enabled.<br> | It's not safe to keep the default user and password logins enabled.<br> | ||
Note! This means that you can only login with the useraccount you just made, so don't loose your password! | <span style="color:red;">Note! This means that you can only login with the useraccount you just made, so don't loose your password!</span> | ||
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. | 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== | ==Change the hostname of the Pi== | ||
Line 41: | Line 41: | ||
You can change this name, by editing these two files: | You can change this name, by editing these two files: | ||
sudo nano /etc/hostname | |||
sudo nano /etc/hosts | |||
Change /etc/hosts into: | Change /etc/hosts into: | ||
127.0.0.1 | 127.0.0.1 localhost | ||
::1 | ::1 localhost ip6-localhost ip6-loopback | ||
ff02::1 | ff02::1 ip6-allnodes | ||
ff02::2 | ff02::2 ip6-allrouters | ||
127.0.1.1 | 127.0.1.1 newhostname (needs to be the same as your hostname) | ||
The hostname will be changed after a reboot. | The hostname will be changed after a reboot. | ||
Line 57: | Line 57: | ||
So reboot and ssh in again. | So reboot and ssh in again. | ||
sudo reboot | |||
ssh USERNAME@ip-address | |||
or | or | ||
ssh USERNAME@HOSTNAME.local | |||
==Install a webserver== | ==Install a webserver== | ||
Line 69: | Line 68: | ||
So we can host webpages on our Pi, that can be reached when we type the ip-address in the browser. | 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: | 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: | And try to check if nginx serves you a file in the browser, by visiting the ip address of your pi, for example: | ||
145.24.131.184 | |||
To edit this page, remove the standard index file and make a new index.html file | To edit this page, remove the standard index file and make a new index.html file | ||
rm /var/www/html/index.nginx-debian.html | |||
nano /var/www/html/index.html | |||
You might get a permission denied error now..... | You might get a permission denied error now..... | ||
This is because the /var/www/html/ is not configured with the right permissions. | This is because the <code>/var/www/html/</code> is not configured with the right permissions. | ||
Let's make a group for all the users on this pi, <br> | Let's make a group for all the users on this pi, <br> | ||
we will give this group the permissions to write in this folder. | we will give this group the permissions to write in this folder. | ||
sudo addgroup USERNAME users | |||
==File Permissions== | ==File Permissions== | ||
Line 117: | Line 118: | ||
rwx rwx rwx | rwx rwx rwx | ||
U | U G O | ||
u = user | u = user | ||
g = group | g = group | ||
o = | o = other | ||
'''user''' has the permission to: rwx ('''read''', '''write''', '''execute''') | |||
'''group''' has the permission to: r-x ('''read''', '''execute''') | |||
'''other''' has the permission to: r-x ('''read''', '''execute''') | |||
Two programs can be used to change '''ownership''' and '''permissions''': | Two programs can be used to change '''ownership''' and '''permissions''': | ||
chown = change ownership | chown = change ownership (Ownership is split up in a '''user''' and a '''group''') | ||
chmod = change | chmod = change modes (Modes are the filesystem permissions given to '''user''', '''group''' and '''others''' classes to access files under Unix.) | ||
To see the permissions of the /var/www/html folder | To see the permissions of the /var/www/html folder | ||
ls -l /var/www/ | |||
Outputs: | Outputs: | ||
Line 142: | Line 147: | ||
d rwx r-x r-x | d rwx r-x r-x | ||
U | U G O | ||
U = rwx | |||
G = r-x | |||
O = r-x | |||
owned by user: root | owned by '''user''': root | ||
owned by group: root | owned by '''group''': root | ||
We want to change the permissions and ownership to: | We want to change the permissions and ownership to: | ||
user: root (or anything else) | |||
group: users (this is the shared group that we just made) | |||
G = rwx ('''read''', '''write''' and '''execute''' permissions) | |||
To '''change ownership''' to '''user=root''' and '''group=users''': | |||
chown -R root:users /var/www/html/ | |||
To change | To '''change permissions''' of '''group''': | ||
chmod -R g+w /var/www/html/ | |||
Check if it worked: | Check if it worked: | ||
ls -l | |||
And try to edit the index.html file now in /var/www/html/ | And try to edit the '''index.html''' file now in /var/www/html/ | ||
nano /var/www/html/index.html |
Latest revision as of 19:18, 11 March 2021
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
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, for example:
145.24.131.184
To edit this page, remove the standard index file and make a new index.html file
rm /var/www/html/index.nginx-debian.html
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 = other
user has the permission to: rwx (read, write, execute) group has the permission to: r-x (read, execute) other has the permission to: r-x (read, execute)
Two programs can be used to change ownership and permissions:
chown = change ownership (Ownership is split up in a user and a group) chmod = change modes (Modes are the filesystem permissions given to user, group and others classes to access files under Unix.)
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
U = rwx G = r-x O = r-x
owned by user: root owned by group: root
We want to change the permissions and ownership to:
user: root (or anything else) group: users (this is the shared group that we just made) G = rwx (read, write and execute permissions)
To change ownership to user=root and group=users:
chown -R root:users /var/www/html/
To change permissions of 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