Skip to content

Instantly share code, notes, and snippets.

@PaulMarisOUMary
Created November 19, 2021 22:04
Show Gist options
  • Save PaulMarisOUMary/791a572c8635b757aaece37dcc06d325 to your computer and use it in GitHub Desktop.
Save PaulMarisOUMary/791a572c8635b757aaece37dcc06d325 to your computer and use it in GitHub Desktop.
Raspberry PI OS Lite: setting up, configure, users, SSH, style, MOTD

Index

Setup

Default Raspberry PI OS credentials

login: pi password: raspberry

⚠️ You should have your keyboard configured in QWERTY US.

Configure keyboard with raspi-config

sudo raspi-config

Navigate in the menu with arrows keys and select with enter key.

Select Localisation Options

raspiconfig-root-5

Select Change Keyboard Layout

raspiconfig-localisation-3

Then then follow the instruction and select your configuration.

Change the hostname with raspi-config

sudo raspi-config

Select System Options

raspiconfig-root-1

Select Hostname

raspiconfig-system-4

Then provide a name for your server.

Update your system

sudo apt-get update
sudo apt-get upgrade

❗ The upgrade should ask for consent, type yes.

Users

Change root password

sudo passwd root
# Then enter the password for your the super-user.

❗ On Raspberry PI OS you won't see anything when you'll type your password. This is normal this is a Security option, each keys are reccorded (in the password field).

Change default pi password

sudo passwd pi

Rename default pi user

⚠️ You must be logged in on a different account than the one you want to modify, in our case lets login as a super-user : root. Exit your session.

exit

Log-in as root. Then change the default username with.

usermod -l yourusername pi
usermod -m -d /home/yourusername yourusername

❗ Replace yourusername with your username.

Disable Wireless Wifi

Disable the Wireless Local Area Network (WLAN aka Wireless Wifi)

⚠️ If your raspberry use the Ethernet interface (ETH) and you want to disable the Wireless Local Area Network (WLAN) type :

Temporarily disable the WLAN

The effects of this command will be reset on reboot.

ifconfig wlan0 down

Permenant disable the WLAN

This command disable the wifi and it will stay off on reboot.

dtoverlay=disable-wifi

➕ Bonus : disable the bluetooth with dtoverlay=disable-bt.

SSH

Enable the SSH

As user enable the SSH with :

sudo raspi-config

Select Interface Options

raspiconfig-root-3

Select SSH

raspiconfig-interface-2

Select Yes

raspiconfig-interface-enablessh

Your SSH is now live ! If you want to connect to your server inside your local network : type ifconfig save the inet 192.168.1.XX. Then in a cmd shell type ssh username@yourlocalip.

❗ Replace username with your username (example : pi); yourlocalip with your local IP adress. Example : ssh paul@192.168.1.42

Access to your SSH on internet

Configure the NAT (Network Address Translation) page in your router. In your browser (Google Chrome or any) type : http://192.168.1.1/

Find your NAT page on your router (may be on Network v4 menu). Then add a Redirection with the following parameters.

External Port : 22 Destination Port : 22 Protocol : TCP Target IP : 192.168.1.XX

❗ Replace the 192.168.1.XX with the inet value in ifconfig. :warning: Setting names may vary in order to your network provider.

Then find your router IP adress and in a cmd shell type ssh yourusername@yourIP. Example : ssh paul@108.177.16.0

Allow SSH connection as root

sudo nano /etc/ssh/sshd_config

Scroll and change the PermitRootLogin setting to PermitRootLogin yes.

❗ Save with CTRL + X type y then enter .

MOTD - SSH

Hide last login message on connecting SSH

sudo nano /etc/ssh/sshd_config

Scroll and change the PrintLastLog setting to PrintLastLog no.

❗ Save with CTRL + X type y then enter .

Custom MOTD message with colors

Change the default MOTD (Message Of The Day).

sudo nano /etc/update-motd.d/10-uname

Following this color map replace $(tput setaf colornumberhere) with the color you want. colors-code-256

The following example will display a cat on the user session when connecting. Paste the following code and "edit the cat".

#!/bin/sh
export TERM=xterm-256color

echo "
$(tput setaf 5)
       _                        
       \`*-.                    
        )  _`-.                 
       .  : `. .                
       : _   '  \               
       ; *` _.   `*-._          
       `-.-'          `-.       
         ;       `       `.     
         :.       .        \    
         . \  .   :   .-'   .   
         '  `+.;  ;  '      :   
         :  '  |    ;       ;-. 
         ; '   : :`-:     _.`* ;
     .*' /  .*' ; .*`- +'  `*' 
      `*-*   `*-*  `*-*'

$(tput sgr0)"

Everything inside the echo " text here " will be displayed (except for the color represented by $(tput setaf colornumberhere)).

You can delete everything if you don't want to display the text.

Additional MOTD text with color

sudo nano /etc/motd

You can add color with the following map of color codes :

Black          0;30     Dark Gray     1;30
Red            0;31     Light Red     1;31
Green          0;32     Light Green   1;32
Brown/Orange   0;33     Yellow        1;33
Blue           0;34     Light Blue    1;34
Purple         0;35     Light Purple  1;35
Cyan           0;36     Light Cyan    1;36
Light Gray     0;37     White         1;37

Example :

^[[H^[[2J
^[[01;31m
       _                        
       \`*-.                    
        )  _`-.                 
       .  : `. .                
       : _   '  \               
       ; *` _.   `*-._          
       `-.-'          `-.       
         ;       `       `.     
         :.       .        \    
         . \  .   :   .-'   .   
         '  `+.;  ;  '      :   
         :  '  |    ;       ;-. 
         ; '   : :`-:     _.`* ;
     .*' /  .*' ; .*`- +'  `*' 
      `*-*   `*-*  `*-*'

^[[0m

⚠️ Don't write ^ + [, press esc + v + esc to create this special character.

You can delete everything if you don't want to display the text.

Customise the primary prompt

Each user can customise his primary prompt with: Example you can repeat this operation as root, pi, etc...

sudo nano ~/.bashrc

Edit the PS1 value on this line on any user (except root)

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;95m\]\w \$\[\033[00m\] '

Symbols meanning :

\u = username
\h = hostname
\w = current working directory

Do the same thing logged in as root.

Bonus

Additional usefull instalations

sudo apt-get install python3-pip #pip (package manager for python3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment