Install RetroPi on Raspberry 4

This How To Install RetroPi on Raspberry 4 helps you to in simple steps create a RetroPi Gaming Machine on your Raspberry Pi 4. The how to leverages on the official RetroPi sources allowing to play hundreds of games!

Install RetroPi on Raspberry 4

Install RetroPi on Raspberry 4

 

Index of Install RetroPi on Raspberry 4

Background 

For this how to i have used a standard Raspberry Pi, as well as standard software available under the open source license on the internet.

How To Install RetroPi on Raspberry 4

To get the RetroPi on Raspberry 4 running, we will go thru several steps.

First step: Download and Install

We will be downloading the official Raspberry Pi 4 image from the official RetroPi website. Following this, we will put the image on a USB storage device (USB  stick) that later will be plugged into the Raspberry Pi. The aim is to operate the gaming machine from a USB storage device, and not from a SD card that typically is leveraged on for a Raspberry Pi. The reason is, USB storage devices are far more reliable than SD cards.

  • Download the RetroPi Image. Since we install a Raspberry Pi 4, we leverage on the Raspberry Pi 4/400 image. Once downloaded, it will be called like “retropie-buster-4.8-rpi4_400.img”
  • Download the official Raspberry Pi OS Imager. Once downloaded it will be called like “imager_1.7.3.dmg”. In this case its the Mac version.
  • Install the Raspberry Pi OS Imager
  • Start the Raspberry Pi OS Imager. This will look like this:
    Raspberry Pi Imager v1.7.3

    Raspberry Pi Imager v1.7.3

  • In the Raspberry Pi Imager tool select now “CHOOSE OS”
  • Go down until you see “Use custom”. Click “Use custom” and a window to select the *.img file will open. You select the before downloaded RetroPi Image that is called something like “retropie-buster-4.8-rpi4_400.img”.
  • Now you insert your USB storage device (e.g. USB stick) which you like to use for your RetroPi installation. Alternatively, you certainly can leverage on an SD card. The procedure will be the same. Going forward we however focus on the USB storage device.
  • In the Raspberry Pi Imager tool select “CHOOSE STORAGE”. Select the USB storage device (alternatively the SD card)
  • Before clicking on “WRITE”, lets enable remote SSH login as well as the network configuration. To do so, click the Settings option like shown in the below picture:
    Raspberry Pi Imager Settings

    Raspberry Pi Imager Settings

  • Configure the SSH login, including the username “pi” and a password that you like to note down in a secure manner. Furthermore and to simplify life, configure also your WiFi network. This will be needed in the next steps. Alternatively, we leverage in the next steps on a LAN cable. Once done, hit “SAVE”
  • Back to the Raspberry Pi Imager main screen, click on “WRITE”. Depending on the speed of your computer and the USB storage device or SD Card this will take now a while….
  • Once done, plug the USB stick into your Raspberry Pi 4 and go to the next step, step two.

Second Step: Initial Configuration

After the first step is complete, we assume now you have ready your Raspberry Pi 4 with the freshly written USB stick. You plug the USB stick into your Raspberry, connect your screen and keyboard and you start your Raspberry Pi 4 the first time. To increase the speed to a maximum possible, and assuming you leverage on a USB 3.1 ready USB stick, you would like to plug the USB stick into one of the blue USB ports. The blue USB ports are the USB 3.1 ports that allow a higher speed.

Once you started the Raspberry Pi, you will find automatically the graphical interface of the RetroPi asking you to install your controllers. This is exactly what you do now. You configure the game controllers in order to be able to deal with the RetroPi. Following this, you end up in the main menu. Lets do now the most important configurations.

Update the system

On the RetroPi main screen select:

  • Select RetroPi: Configuration
  • Select RetroPi Setup; a command line based menu will open
  • Select “I Basic Install”
  • Confirm by “yes”. This will most likely take now a while
  • Back in the main menu select “U Update”
  • Confirm by “yes”
  • Once more, confirm by “yes” for updating the underlying Operating System

This is done now.

Activate SSH

The activation of SSH allows to remotely copy files, such as for example the needed ROMs to play games to the Raspberry. In order to configure SSH securely execute the do the 4 steps :

Step 1, generate certificates:

ssh-keygen -t ed25519 -C "Your@E-MailAddress.com"

The input/output should look similar like the below. Please note, not setting a passphrase allows an easier user experience for logging in, but is however also more risky as it potentially allows anyone to login that is able to steel your private key

pi@retropi:~$ ssh-keygen -t ed25519 -C "Your@E-MailAddress.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/pi/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/pi/.ssh/id_ed25519
Your public key has been saved in /home/pi/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:iic0RyBXlhKNmvr7OxS8z95dcdRi8EmQRpsXG1J3zeE OpenHAB3
The key's randomart image is:
+--[ED25519 256]--+
|  . +=o.   .=+=o=|
|   oooo     oB.B+|
|   + ..    .o OE.|
|  o o.       + . |
| .  oo. S   . .  |
|.  .o+ .     o   |
| . .ooo     .    |
|  . .oo. . .     |
|  .oo+. . .      |
+----[SHA256]-----+


Step 2, generate certificates on your computer

In this step we leverage on a Mac computer and we leverage on the Mac’s command line. If you run a Windows system you like to leverage on your favourite software.

Mike@Mac-Mini ~ % ssh-keygen -t ed25519 -C "Your@E-MailAddress.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/Mike/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /users/Mike/id_ed25519
Your public key has been saved in /users/Mike/id_ed25519.pub
The key fingerprint is:
SHA256:D38BRm81OT5jE5AtD+eCHXG77tNNQUhnC1jGk7Bsw3g test
The key's randomart image is:
+--[ED25519 256]--+
|          ..OX*+ |
|         .+oBBX+.|
|         .oEoO++ |
|         .+o+ Oo |
|        S   .o.+.|
|         +   o  .|
|          o . .o.|
|           . .. o|
|              .. |
+----[SHA256]-----+


Step 3, copy your public certificate to the RetroPi system

This step is now a simple copy and paste activity. You copy the content of your in step 2 generated id_ed25519.pub file into the authorized_key file on RetroPi.

nano /home/pi/.ssh/authorized_keys

 Try to login by leveraging on SSH. For example, if your RetroPi IP address is 192.168.1.100, than by typing the below

ssh pi@192.168.1.100

If all runs well, than you should be able to login without typing a password as SSH will be leveraging on your keys.

Step 4, Hardening of ssh.conf

A important step in this hardening process is to ensure the right configuration of SSH. SSH stores its configuration in ssh.conf. In this step 4 we now will be updating ssh.conf in a way in which your RetroPI will allow login by SSH key only, but not anymore by passwords. With this you mitigate the high risks related to passwords (Password guessing, brute force attacks, etc.)

sudo vi /etc/ssh/sshd_config

Allow Only ed25519 Key Login

To activate login by the above created ed25519 key only change the following lines from

#HostKey /etc/ssh/ssh_host_ed25519_key
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2


to

HostKey /etc/ssh/ssh_host_ed25519_key
AuthorizedKeysFile     .ssh/authorized_keys 


Allow Only Key Login (no password login anymore)

To activate login by key only (no password anymore) set Password Authentication to no. Additionally, disallow login with empty passwords. Therefore, change the following lines from

#PasswordAuthentication yes 
#PermitEmptyPasswords no

to

PasswordAuthentication no
PermitEmptyPasswords no

Disable Root Login

You do not like that anyone logs into your RetroPi remotely by leveraging on Root. Therefore, disallow root login. This you do by changing the below line from:

#PermitRootLogin prohibit-password

to:

PermitRootLogin no

Only Allow The More Secure Protocol 2

There are tow protocol versions of SSH, Protocol 1 and Protocol 2. Protocol 1 is legacy and Protocol 2 is more secure. Most likely, your sshd_config does not consist of a setting. You however can simply add the below line at the end of your sshd_config file:

Protocol 2

Protect Against Unattended Sessions

Leaving your RetroPi unattended for a long time period carries security risks. Therefore you like to address the issue by setting a limit for keeping a session open if not used. In this example we set the limit to 180 second. SSH will close the session once idle for 180 seconds. Change from:

#ClientAliveInterval 6

to:

ClientAliveInterval 180

Allow Only Selected Users To Login By SSH

Allow only users you know to login into your RetroPi. By default the user is “pi”. In this example we allow only the “pi” user to login leveraging on SSH. Add the below line to the end of your sshd_config:

AllowUsers pi

Maximum Number Of Trying The Password

Even though we have allowed in the above only login by key, we still like to limit the number of passwords attempts to 3 tries. Change from:

#MaxAuthTries 6

to:

MaxAuthTries 3

Make The New Configuration Effective And Test It

Last step is to test your updated configuration. To do so, you keep your existing terminal open. Do not close it, because you will need it if your configuration does not work. We try the configuration in 2 steps. First, in the existing window we type and execute:

sudo systemctl restart sshd

2nd, in a new additional terminal window (open a new terminal window and keep the existing open) you type:

ssh pi@

“IP ADDRESS OF YOUR RetroPi”

If you able to login, great. Your configuration works. If not, double check in the other Terminal window that you have not closed your configuration for potential mistakes.

Finally, you can test some of your configurations whether they work properly. Open a Terminal window and test whether login with Protocol 1 is possible (it should not be possible) and it should look like this:

testuser@Mac-mini ~ % ssh -1 pi@”IP ADDRESS OF YOUR RetroPi”
SSH protocol v.1 is no longer supported
testuser@Mac-mini ~ %

Test whether you can login as root and if the root user as configured in the above is not allowed to login, than it should look like this:

testuser@Mac-mini ~ %  ssh root@"IP ADDRESS OF YOUR RetroPi"
root@"IP ADDRESS OF YOUR RetroPi": Permission denied (publickey).
testuser@Mac-mini ~ % 


Third step: Find and Upload ROM files (Games)

In order to play games, you need to have so called ROM files. ROM stays for Read Only Memory. These format was used in the past for games, such as Nintendo, Game Bay, Amiga, etc. 

To find games you best leverage on Google. There are games for free, but also there are games to buy.

Once you found and downloaded ROM files, then you can easily copy them to the target folder, leveraging on SSH (SCP). Either you use Putty, for example in windows or you do that much faster via command line like you for example can do on a Mac or Linux based computer.

To leverage on SCP, run the following:

scp -r /Users/Mike/Downloads/psx/ pi@192.168.1.100:/home/pi/RetroPie/roms/psx/

This would copy all ROMs from the local folder /Users/Mike/Downloads/psx to the RetroPi folder /home/pi/RetroPi/roms/psx

  • Source Folder (in this case on a local Mac): /Users/Mike/Downloads/psx 
  • Destination Folder on the Retro Pi (in this case Playstation, hence “psx”): /home/pi/RetroPie/roms/psx/ 
  • RetroPi IP Address and Username (username in this case “pi”): pi@192.168.1.100:

Restart the RetroPi Emulation now and you should find the uploaded games.

Enjoy!

Additional Information

If you like to install RetroPi on an existing Raspberry without leveraging on the RetroPi Image, follow this How To Transform Raspberry Into A Gaming Machine.

Find out more about security for your fresh installed Raspberry! There are a couple of recommendations that will not hinder you having fun, but some of them even make your life easier whilst increasing considerably the security of you system (for example SSH login by keys instead of passwords). The Hardening of OpenHAB Guide should help you to a large extend for making your system secure. Maybe, at a later stage I am going to write a dedicated guide for RetroPi.

Follow me

It would be amazing if you follow myHowTo.blog. To follow leverage on

  • Click to follow me on Twitter
  • Bookmark this page and comeback from time to time

Help and Comments

I am really looking forward for you to contact me if for example you found a better option or other idea then in this how to. Also, please touch base if you found an error or anything not working or if you have something that you would love to be added to this how to. Simply click this link to touch base with me.

Linking and Recommending the HowTo or the myhowto.blog

I would love to see you are recommending this how to or link it to your website. Also, I would love if you link or recommend the whole myhowto.blog. Please feel free to do so! In case you like to touch base regarding this topic with me, then simply click this link. I look forward!