RaspberryPi #5: your TTY “Desktop” computer

How to use your RPi as a fast text-only (TTY) computer

Raspberry Pi 3, TTY session using Tmux (so much fun!)

Prepare your RPi

Basics: configure your RPi, and remember all the setup can be done ‘headless’, without plugging in a keyboard, mouse and screen.

My advice for this project: go for the Raspberry OS Lite version, as we won’t need any desktop environment for this project.

The steps to prepare the SD Card are detailed here, you’ll just need a 4Gb SDcard, any computer, and the Raspberry Imager. The application will take care of downloading and copying the right version on the SDcard:

$ sudo apt install rpi-imager

Once Imager have copied the files on the SDcard, don’t eject it yet. You’ll need to additional files to allow Internet and SSH connections.

SSH connection

This section describes how to configure your RPi with no mouse/keyboard no screen, just using another computer. It’s not necessary if you have the hardware but it’s a fun way to start the project!

So at this point you should have added 2 elements to your SDcard:

  • A wpa_supplicant.conf file at the root of the /boot folder that has your Wifi SSID and password. The file will be erased after the first boot:
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicantnetwork={
scan_ssid=1
ssid="MyNetworkSSID"
psk="Pa55w0rd1234"
}
  • An empty file named ssh (no extension) at the root of the /boot folder on your SD Card. This file will allow SSH connection to the Raspberry

Start the Pi

Now’s the time to start the RPi!

Now, in order to connect to your Raspberry Pi from another machine using SSH we need to identify the device’s IP address. Since we already activated the Wifi, the Pi should appear on your network. Use the nmap command to identify your devices:

$ sudo nmap -sn 192.168.49/24

You should find a “Raspberry Pi Foundation” device:

> Nmap scan report for 192.168.1.40
> Host is up (0.23s latency).
> MAC Address: B8:27:EB:6A:4A:99 (Raspberry Pi Foundation)

You can now SSH into the Raspberry from your desktop. The default login / password of your Pi is pi / raspberry.

$ ssh pi@192.168.1.40

Should you need to reset any old host key and allow connection, enter the following command:

$ ssh-keygen -R 192.168.1.40

Upgrading your TTY

You start with a standard TTY (6 actually, from Ctrl+Alt F1 to F6).

Set font & size

$ sudo dpkg-reconfigure console-setup

UTF8 / Latin — Combined / TerminusBold / 10x20

Set the colorscheme

Bash prompt and colorscheme are set in your .bashrc file:

$ vim ~/.bashrc

Custom prompt:

# custom prompt
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\u \[\e[0m\]in \[\033[01;32m\]\w \[\033[01;35m\]λ\[\e[0m\] '
else
# will be display as TTY:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\u \[\e[0m\]in \[\033[01;32m\]\w \[\033[01;35m\]λ\[\e[0m\] '

fi
unset color_prompt force_color_prompt

Example with Dracula colorscheme:

# TTY font colors
if [ "$TERM" = "linux" ]; then
printf %b '\e[40m' '\e[8]' # set default background to color 0 'dracula-bg'
printf %b '\e[37m' '\e[8]' # set default foreground to color 7 'dracula-fg'
printf %b '\e]P0282a36' # 'black' as 'dracula-bg'
printf %b '\e]P86272a4' # 'bright-black' as 'dracula-comment'
printf %b '\e]P1ff5555' # 'red' as 'dracula-red'
printf %b '\e]P9ff7777' # 'bright-red' as '#ff7777'
printf %b '\e]P250fa7b' # 'green' as 'dracula-green'
printf %b '\e]PA70fa9b' # 'bright-green' as '#70fa9b'
printf %b '\e]P3f1fa8c' # 'brown' as 'dracula-yellow'
printf %b '\e]PBffb86c' # 'bright-brown' as 'dracula-orange'
printf %b '\e]P4bd93f9' # 'blue' as 'dracula-purple'
printf %b '\e]PCcfa9ff' # 'bright-blue' as '#cfa9ff'
printf %b '\e]P5ff79c6' # 'magenta' as 'dracula-pink'
printf %b '\e]PDff88e8' # 'bright-magenta' as '#ff88e8'
printf %b '\e]P68be9fd' # 'cyan' as 'dracula-cyan'
printf %b '\e]PE97e2ff' # 'bright-cyan' as '#97e2ff'
printf %b '\e]P7f8f8f2' # 'white' as 'dracula-fg'
printf %b '\e]PFffffff' # 'bright-white' as '#ffffff'
clear
fi

First look with a simple ls command:

Terminal Multiplexer: TMUX

$ sudo apt install tmux

Create a ~/.tmux.conf file to customize Tmux. Here is my config file including a few tweaks and shortcuts modification:

$ vim ~/.tmux.conf---# CUSTOM ~/.tmux.conf

##################################
# KEYS
##################################
# change Control+b > Control +x
set -g prefix C-x
unbind C-b
bind C-x send-prefix

# start with window 1 (instead of 0)
set -g base-index 1
# start with pane 1
set -g pane-base-index 1
# split panes using | and -, make sure they open in the same path
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# control + arrows
bind -n C-right next
bind -n C-left prev

# switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
# reload config file
bind r source-file ~/.tmux.conf
##################################
# MOUSE
##################################
set -g mouse on
# Enable locking
set -g lock-command vlock
set -g lock-after-time 0 # Seconds; 0 = never
bind L lock-session
######################
### DESIGN CHANGES ###
######################
# loud or quiet?
set -g visual-activity off
set -g visual-bell off
set -g visual-silence off
setw -g monitor-activity off
set -g bell-action none
# modes
setw -g clock-mode-colour colour5
setw -g mode-style 'fg=colour1 bg=colour18 bold'
# panes
set -g pane-border-style 'fg=colour19 bg=colour0'
set -g pane-active-border-style 'bg=colour0 fg=colour9'
# statusbar
set -g status-position bottom
set -g status-justify left
set -g status-style 'bg=colour18 fg=colour137 dim'
set -g status-left ''
set -g status-right '#[fg=colour233,bg=colour19] %d/%m #[fg=colour233,bg=colour8] %H:%M:%S '
set -g status-right-length 50
set -g status-left-length 20
setw -g window-status-current-style 'fg=colour1 bg=colour19 bold'
setw -g window-status-current-format ' #I#[fg=colour249]:#[fg=colour255]#W#[fg=colour249]#F '
setw -g window-status-style 'fg=colour9 bg=colour18'
setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '
setw -g window-status-bell-style 'fg=colour255 bg=colour1 bold'# messages
set -g message-style 'fg=colour232 bg=colour16 bold'

Start Tmux:

$ tmux

There it is, open new terminal panes with binding ctrl + xfollowed by |ou -to split vertically or horizontally:

On the screen: Vim, Cmus, Exa ls, Ranger.

CLI tools

A few CLI tools to use with your TTY machine:

  • File manager: ranger
  • Text editor: vim
  • Music player: cmus
  • Screenshots: fbcat
  • Process viewer: htop
  • Spec viewer: neofetch
  • LS improvement: exa
  • Fun: cmatrix, lolcat

Have fun!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rphl-Mstl

Rphl-Mstl

106 Followers

OS explorer, UI & UX passionate, Voxels crafter, code lover, Video Games player, Podcasts listener, Music amateur // Digital Publishing professional