The Pi is installed now what do we do?: Difference between revisions

From XPUB & Lens-Based wiki
(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...")
 
No edit summary
Line 5: Line 5:
Making a new user on the Pi
Making a new user on the Pi


    sudo adduser USERNAME
sudo adduser USERNAME


Add this user to the sudo group
Add this user to the sudo group


    sudo addgroup USERNAME GROUPNAME
sudo addgroup USERNAME GROUPNAME


    sudo addgroup USERNAME sudo
sudo addgroup USERNAME sudo


Logout of the current ssh connection
Logout of the current ssh connection


    exit
exit


Now log in with your new user
Now log in with your new user


    ssh user@ipadress
ssh user@ipadress


Try to see if your sudo powers work
Try to see if your sudo powers work


    sudo test
sudo test


Let's remove the user "pi". <br>
Let's remove the user "pi". <br>
Line 29: Line 29:
Note! This means that you can only login with the useraccount you just made, so don't loose your password!
Note! This means that you can only login with the useraccount you just made, so don't loose your password!


    sudo deluser pi
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
sudo reboot
    ssh USERNAME@ip-adress
ssh USERNAME@ip-adress
    sudo deluser pi
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/hostname
    sudo nano /etc/hosts
sudo nano /etc/hosts


Change /etc/hosts into:  
Change /etc/hosts into:  


  127.0.0.1       localhost
  127.0.0.1   localhost
  ::1             localhost ip6-localhost ip6-loopback
  ::1   localhost ip6-localhost ip6-loopback
  ff02::1         ip6-allnodes
  ff02::1   ip6-allnodes
  ff02::2         ip6-allrouters
  ff02::2   ip6-allrouters
   
   
  127.0.1.1       newhostname (needs to be the same as your hostname)
  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
sudo reboot
    ssh USERNAME@ip-address
ssh USERNAME@ip-address


or
or


    ssh USERNAME@HOSTNAME.local
ssh USERNAME@HOSTNAME.local
    (doesn't seem to work in the studio unfortunately, but at home this might work)
(doesn't seem to work in the studio unfortunately, but at home this might work)


==Install a webserver==
==Install a webserver==
Line 69: Line 69:
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
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/
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:


    145.24.131.184
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


    sudo nano /var/www/html/index.html
sudo nano /var/www/html/index.html


You might get a permission denied error now.....
You might get a permission denied error now.....
Line 90: Line 90:
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
sudo addgroup USERNAME users


==File Permissions==
==File Permissions==
Line 117: Line 117:


  rwx rwx rwx
  rwx rwx rwx
  U     G   O
  U G O


  u = user
  u = user
Line 130: Line 130:
To see the permissions of the /var/www/html folder
To see the permissions of the /var/www/html folder


    ls -l /var/www/
ls -l /var/www/


Outputs:  
Outputs:  
Line 142: Line 142:


  d rwx r-x r-x  
  d rwx r-x r-x  
   U     G  O
   U G  O


  owned by user: root
  owned by user: root
Line 149: Line 149:
We want to change the permissions and ownership to:
We want to change the permissions and ownership to:


    user: root (or anything else)
user: root (or anything else)
    group: users
group: users
    G = rwx
G = rwx


To change ownership to user=root and group=users:
To change ownership to user=root and group=users:


    chown -R root:users /var/www/html/
chown -R root:users /var/www/html/




To change the write permissions to the group:
To change the write permissions to the group:


    chmod -R g+w /var/www/html/
chmod -R g+w /var/www/html/


Check if it worked:
Check if it worked:


    ls -l
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
nano /var/www/html/index.html

Revision as of 19:21, 4 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
(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