Monday, October 21, 2019

How to Setup and Use SSH on a Raspberry PI

How to Setup and Use SSH on a Raspberry PI SSH is a secure method of logging onto a remote computer. If your Pi is networked, then this can be a handy way of operating it from another computer or just copying files to or from it. First, you have to install the SSH service. This is done by this command: sudo apt-get install ssh After a couple of minutes, this will be complete. You can start the daemon (Unix name for a service) with this command from the terminal: sudo /etc/init.d/ssh start This init.d is used to start other daemons. For example, if you have Apache, MySQL, Samba etc. You can also stop the service with stop or restart it with restart. Have It Start at Bootup To set it up so the ssh server starts every time the Pi boots up, run this command once: sudo update-rc.d ssh defaults You can check that it worked by forcing your Pi to reboot with the reboot command: sudo reboot Then after rebooting try to connect to it using Putty or WinSCP (details below). Powering Down and Rebooting Its possible to corrupt your SD card with power offs before it halts. The result: reinstall everything. Only power down once you have fully shut down your Pi. Given its low power usage and little heat given off, you could probably leave it running 24x7. If you want to shut it down, use the shutdown command: sudo shutdown -h now Change -h to -r and it does the same as sudo reboot. Putty and WinSCP If youre accessing your Pi from the command line of a Windows/Linux or Mac PC then use Putty or the commercial (but free for private use) Tunnelier. Both are great for general browsing around your Pis folders and copying files to or from a Windows PC. Download them from these URLs: Putty Download PageWinSCP Download PageTunnelier: Powerful free to use Windows SFTP etc. Your Pi needs to be connected to your network before you use Putty or WinSCP and you need to know its IP address. On my network, my Pi is on 192.168.1.69. You can find yours by typing in /sbin/ifconfig and on the 2nd line of the output, youll see inet addr: followed by your IP address. For Putty, its easiest to download putty.exe or the zip file of all the exes and put them in a folder. When you run putty it pops up a configuration Window. Enter your IP address in the input field where it says Host Name (or IP address) and enter pi or any name there. Now click the save button then the open button at the bottom. Youll have to login into your pi but now you can use it as if you were actually there. This can be quite useful, as its far easier to cut and paste long text strings in via a putty terminal. Try running this command: ps ax That shows a list of processes running on your pi. These include ssh (the two sshd) and Samba (nmbd and smbd) and many others. PID TTY STAT TIME COMMAND858 ? Ss 0:00 /usr/sbin/sshd866 ? Ss 0:00 /usr/sbin/nmbd -D887 ? Ss 0:00 /usr/sbin/smbd -D1092 ? Ss 0:00 sshd: pi [priv] WinSCP We find it most useful to set it up in two screen mode rather than in explorer mode but its easily changed in the Preferences. Also in preferences under Integration/Applications change the path to the putty.exe so you can easily jump into putty. When you connect to the pi, it starts at your home directory which is /home/pi. Click on the two .. to view the folder above and do it once more to get to the root. You can see all of the 20 Linux folders. After youve used a terminal for a while youll see a hidden file .bash_history (not that well hidden!). This is a text file of your command history with all the commands youve used before so copy it, edit out the stuff you dont want and keep the useful commands somewhere safe.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.