Raspberry Pi - Enabling SSH for Remote Access
For some applications you may not want your Raspberry Pi permanenenty attached to a monitor and keyboard or perhaps you just would like to be able to access your Raspberry Pi remotely. Enabling the SSH server on your Raspberry Pi will provide SSH terminal access over your network. This article will cover the steps need to enable the SSH server for remote access and how to connect to the Raspberry Pi using a SSH terminal enumation software from Windows and Mac OSX.
Enable SSH Server on Raspberry Pi
NOTE:
If you are running the Raspian "Wheezy" image or the Debian "Wheezy" image, please note that SSH is already enabled by default. You can also use the Raspberry configuration utility to enable/disable the SSH server by running the command and selecting the SSH item from the menu:
sudo raspi-configYou can skip this section and proceed to the next section in the article.
From the console on the Raspberry Pi please enter the following two commands:
sudo rm /etc/ssh/ssh_host_* sudo dpkg-reconfigure openssh-server
These steps will create the RSA and DSA encryption keys enable the SSH server. The SSH server will also be started automatically each time you reboot your Raspberry Pi.
Now, lets get connected.
Getting the IP Adrress from your Raspberry Pi
Before we can connect remotely, we first need to determine what the IP address is for the Raspberry Pi. For most users, when the Raspberry Pi boots up and is connected to you router/switch/residential gateway it will dynamically obtain an IP address using DHCP.
Use the following command from the console to get the IP adress:
ifconfig
In the resulting output on the screen, look for the inet add for the eth0 device.
Connect from Windows
You can use any terminal emulation software you like; however, for this demonstration we will use Putty a very popular an free terminal software for Windows.
You can download the Putty software here.
Double click the putty.exe program to start Putty. You will be prompted with the Putty configuration dialog. Enter the IP address of your Raspberry Pi in the Host Name field and make sure the the connection type is set to SSH.
To persist these setting so you don't have to re-enter them every time you start Putty, enter a name such as "RaspberyrPi" in the Saved Sessions field and press the Save button.
Click the Open button to connect to the Raspberry Pi and start the SSH session.
You will be prompted with a message to cache the RSA2 fingerprint. Select Yes to accept the key and continue the connection.
Upon connection, you will need to provide the authentication credentials to logon to the Raspberry Pi.
The credentials may vary depending on the operating system image that you installed on your Raspberry. If you loaded Raspian "Wheezy" or Debian "Squeeze" then use username "pi" and password "raspberry".
Now you can interact with your Raspberry Pi just as if you where setting at the keyboard console.
Connect from Mac OSX
No additional software is needed for OSX to connect to the Raspberry SSH server. Just open theTerminal application and enter the ssh command with the username@ip-address format:
ssh pi@10.1.1.194
Upon connection, you will need to provide the authentication credentials to logon to the Raspberry Pi. The credentials may vary depending on the operating system image that you installed on your Raspberry. If you loaded Raspian "Wheezy" or Debian "Squeeze" then use username "pi" and password "raspberry".
Now you can interact with your Raspberry Pi just as if you where setting at the keyboard console.
Reader Comments (6)
Hi there,
When I type "ipconfig" in wheazy it does not recognize the command. My WiFi stick is working correctly and connected to my network. Installed putty on my desktop and talk in to the pi via ssh....... What gives here?
@Nigel,
Sorry, that is a Windows command. It should be "ifconfig" ... I have corrected the article. Thanks for catching this.
No worries, I was a bit confused that's all. Being a windows guy it seemed too natural to me :-)
Hi Robert,
Pls. allow me to add the "how-to" to password-less login into the Raspberry Pi, using a Putty session. Here we go:
1. When you install the Putty suite, "PuttyGen.exe" is also part of it.
2. Run PuttyGen.exe and it will open a Putty Key Generator. Make sure the following is set:
- Type of key to generate: SSH-2 RSA
- Number of bits in a generated key: 4096 (1024 is the default). This guarantees a very secure connection.
3. Click the button "Generate" and move the mouse in the empty area on the top of the dialogue box for as long as the progress bar didn't reach the end. This might take some time, since we set the amount of bits to 4096.
4. After moving around the mouse, the key itself is generated (again, this might take some time, depending on the power of your machine).
5. Press the button "Save private key" and give the key a name (example: raspberry_pi_2.ppk). Make sure you know the location, since you will need that location later on.
6. Open an SSH session, so far still with the "manual" method (that is, passing user name and password).
7. Create a directory ~/.ssh with the permissions 700:
- mkdir /home/pi/.ssh
- chmod 700 /home/pi/.ssh
8. Into the directory /home/pi/.ssh, create a file called "authorized_keys" (beware: authorized with a "z", not an "s"...). Use your favourite editor, e.g. vi.
- vi /home/pi/.ssh/authorized_keys
9. While this file is open in vi (or your preferred Linux command line editor), go back to the PuttyGen dialogue and copy the complete content of the field "Public key for pasting into OpenSSH authorized_keys file:".
10. Go back to the open file in vi (or whatever editor), make sure you can insert text and paste the complete public key into the file.
11. Save the file "authorized_keys"
12. Go back to PuttyGen and close the application (make sure you saved the key file first, see above point 5!).
13. Open Putty and create a new session for the Raspberry Pi (or use an already existing one and load it).
14. Select the item "Connection -> Data" and fill in "pi" for the "Auto-login username"
15. Select the item "Connection -> +SSH" (click on the "+" sign) and then select the item "Auth" (not the "+" sign, just "Auth")
16. At the bottom, indicated by "Private key file for authentication:", browse to the location where you saved your key file, generated by PuttyGen. Select the file.
17. DON'T FORGET TO SAVE THE SESSION!!! THEREFOR:
- Select "Session" in the left part of the dialogue box (scroll to the top to see the item).
- Select the session for which you want to save the item (normally, it should still be selected in the "Saved Sessions" field)
- Press the "Save" button
From now on, when you log into the Raspberry Pi through this Putty session, you won't need your credentials any more...
dartasha e3d3fd1842 https://tchatche.ci/micnyfani
dartasha e3d3fd1842 https://tchatche.ci/micnyfani