Jul 10

Tmux over SSH Raspberry Pi Connection

Creating a Multiple Shell SSH-Connection by running a single script

Recently i bought a Raspberry Pi and wrote a ssh bash-script to connect automatically to Raspbian on the Pi in the LAN. The trick is that the script starts „tmux“ on the Pi. Tmux is a nice tool for creating multiple command lines in one window. By running the script on the Pi multiple SSH-windows appear after running the script.

The result after running the script from an Ubuntu desktop PC will look like this:




sudo apt-get install ssh       ##on Linux-PC

sudo apt-get install expect ##on Linux-PC

sudo apt-get install tmux    ## on Raspberry Pi

Also SSH-server should be activated on Raspbian


The connection Script „sshlogin.sh“ which is launched from the Linux-PC looks like this, adapt your login credentials and the IP of the raspberry pi here (192.168……) :


#!/usr/bin/expect -f

spawn ssh USERNAME@
expect „assword:“
sleep 1
send — „~/tmuxrun.sh\r“
sleep 1


And finally the tmux run script which has to be placed in  „~/tmuxrun.sh“ on Raspbian, can be found here:





If you placed all the files in the right folders and adapted the password and username phrases in the „sshlogin.sh“ you can connect to your Raspberry pi like this:




Making a hotkey binding to the script „sshlogin.sh“ on Linux-PC:

I made this with „xbindkeys“ since the Ubuntu Standard GUI for keybindings wasn’t working properly.

First install xbindkeys on your Linux Machine:


sudo apt-get install xpbindkeys

Then create the configfile for xbindkeys  „~/.xbindkeysrc“ . Add the following text, i used ctrl+alt+p here to start my Raspberry connection since it’s super intuitive:


#SSHLogin with Raspberry Pi
„gnome-terminal -e ~/sshlogin.sh“
control + alt + p

You can launch xbindkeys the by typing „xbindkeys“ in the terminal then. If you launched accidentally with wrong config do „killall xbindkeys“ and relaunch xbindkeys then.Because launching  every time after startup  is a bit much work, i recommend doing the steps described in the next lines.


Make the hotkey binding launch at startup

To make xbindkeys startup on boot open „/etc/rc.local“  and add:




Also make sure the file rc.local is marked as executable  and contains

#!/bin/sh -e

at file start.

xbindconfig will start at next boot then automatically







Schreibe einen Kommentar