How to Use SSH to Connect to Remote Computers Using Windows, Linux or macOS
Connect to a remote machine or server and control it via a command line interface
If you ever need to securely connect to a remote machine and reach a command-line interface, SSH is the tool for the job. The Secure Shell Protocol (SSH) has been used for decades as a means to remotely interface with Unix / Linux / BSD machines over insecure connections.
SSH operates on a traditional client - server principle where a remote user (client) can connect to a server and run commands as if they were sitting at the machine. SSH is particularly useful if you have a server (perhaps on one of the best cheap web hosts) or Raspberry Pi you need to control remotely. As these systems primarily use Linux, it’s easy to do things like edit scripts, change key configuration files or even install software remotely.
In this how to, we will cover how to create basic SSH connections coming from Windows, macOS and Linux machines.
Before You Open SSH: Credentials and Access
To initiate an SSH connection coming from any operating system, you first need proper access to the remote device and you need its address, in the form of either an IP address or a valid hostname. You will need to enter the address to establish your connection and then you will be hit with a request for a username and password.
If you have a web hosting account with SSH enabled, you will likely be able to use the domain name as the address and then the same username and password you employ for reaching FTP or cPanel to log in. If those don’t work, check the instructions on the host’s site. If you are logging into a server on your local network, you will need the computer name / IP address and to make sure that the remote device has an account for you on it.
Using SSH in Windows
Though you can invoke SSH from the command line, most folks much prefer to use PuTTY, a free GUI app that makes connecting easy.
1. Download and install PuTTY. Windows does have its own command prompt, which can be used with SSH, but PuTTY is by far the most accessible means to open an SSH connection.
Stay On the Cutting Edge: Get the Tom's Hardware Newsletter
Get Tom's Hardware's best news and in-depth reviews, straight to your inbox.
2. Open PuTTY. PuTTY’s user interface has a Host Name / IP address section which is where we would type in the details of the machine that we wish to SSH into.
3. Enter the appropriate address into the Hostname or IP address field and click Open.
4. Answer Yes if prompted to confirm your connection. If this is the first time connecting to that system, you will be asked.
You will now be connected to the remote system.
5. Enter your username and password as prompted. The password is not echoed to the screen, this is normal behavior and is a security feature.
You are now in control of the remote machine, any commands will be executed using the remote machine.
6. When finished with the SSH session, type exit and press Enter or simply close the window. It is important to close an SSH session when not in use so you don’t accidentally send commands to it or leave it open should your computer be hacked.
Using SSH in Linux
In all major versions of Linux, SSH is built into the command line and easy to access that way. Note that we used Ubuntu for this tutorial but these instructions would work with almost any Linux flavor.
1. Open the terminal if you’re not already at the command line. Hitting CTRL + ALT + T does this or you can go to the apps menu and search for “terminal” to find its app.
2. Use SSH to log in to the remote machine using your username, and the IP address / hostname. For example our user was “pi” and the hostname was “smartipi,” this is what we’d use:
ssh pi@smartipi.local
3. Type yes if you are given a warning that the SSH connection’s key is not known. This may happen on first connection and you may need to reconnect after entering it.
4. Enter your password if prompted. You won’t see the characters as you type them.
5. Press CTRL + D or type “logout” to finish your session.
Using SSH in macOS
1. Launch the terminal by clicking the terminal icon in the dock.
The terminal is ready for use.
2. Enter the SSH command followed by username@server. In the example below, our user was “pi” and the hostname was “raspberrypi.local”.
ssh pi@raspberrypi.local
3. Type Yes if prompted to confirm the connection for the first time.
4. Enter your password when prompted.
5. When finished with the SSH session, exit using CTRL+D or type exit and press Enter. It is important to close an SSH session when not in use so you don’t accidentally send commands to it or leave it open should your computer be hacked.
How to run a command and close an SSH connection
Sometimes we just need to run a single command on a remote machine. For example this could be a Raspberry Pi that we need to shutdown. Using the -t argument we can log in, run a command, wait for the output and then logout.
1. Open a terminal / command prompt.
2. Use SSH to log in to the remote machine, add “-t” to the end of the command, then insert the command that you wish to run and press Enter. In our example we will login to a Raspberry Pi then run the poweroff command to power down the Pi.
ssh pi@raspberrypi.local -t "sudo poweroff"
3. Enter a password as needed
The remote computer should now log your off and then perform the task.
Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".
-
fancarolina I'm wondering why you used the built in tools for Linux and MacOS but did not use PowerShell for Windows. Simply open a PowerShell Window and type "ssh user@ipaddress" no need to install a 3rd Party Application. Is Putty a nice option yes but it just seems inconsistent with the rest of the choices.Reply -
BillyBuerger I also have been using WSL along with the Terminal app on Windows for many years now. SSH is there ready to go to connect to my home linux server when needed. Although good to know that PowerShell has SSH built in as well. But I've never really gotten into using PowerShell much. I use old school command line for actual Windows (DOS) stuff and WSL for everything else.Reply -
kal326 Weird they didn’t even touch on cert based auth. SSH is handy for sure, but this article is seriously lacking in some basic security instructions. It’s like telling people you can getting remote access to your home windows box by port forwarding the rpd port from your firewall. Eventually it’s going to get hacked.Reply -
mik8142
Agreed, at least puttygen, if putty already mentioned in articlekal326 said:Weird they didn’t even touch on cert based auth. SSH is handy for sure, but this article is seriously lacking in some basic security instructions. It’s like telling people you can getting remote access to your home windows box by port forwarding the rpd port from your firewall. Eventually it’s going to get hacked. -
ezst036 PuTTY is also available for Linux.Reply
Please stop perpetuating the myth that Linux is unusable unless everything is done on the command line. This isn't the 1990's anymore.
-
HappyColoredMarbles I think the coolest thing about SSH is the simple code. SSHHHHHHHHHHHHH. Remember: pirates stole America from the Indians. And you must steal money from the top 1%.Reply -
HappyColoredMarbles
Today I learned for MacOS to Linux, there are some additional preliminary rudimentary steps to further encrypt. It's ingenious but quite frustrating.fancarolina said:I'm wondering why you used the built in tools for Linux and MacOS but did not use PowerShell for Windows. Simply open a PowerShell Window and type "ssh user@ipaddress" no need to install a 3rd Party Application. Is Putty a nice option yes but it just seems inconsistent with the rest of the choices. -
HappyColoredMarbles
I like command line for security. But GUI is nice. Maybe once I get the basics figured out I might look for additional installations for comfort. But you have to crawl before you run. If you don't know how to work with legacy systems you run the risk of being locked out from your parents will.ezst036 said:PuTTY is also available for Linux.
Please stop perpetuating the myth that Linux is unusable unless everything is done on the command line. This isn't the 1990's anymore.
-
HappyColoredMarbles
Yes. I've been working on the application of applied entropy to my code libraries for increased security. I agree; a writer tasked with teaching children shouldn't hide the truth. I have been following my tail because of ad revenue. But part of the security of this type of transfer is the tribal knowledge base. My code library is currently valued at about $3.14159 billion.kal326 said:Weird they didn’t even touch on cert based auth. SSH is handy for sure, but this article is seriously lacking in some basic security instructions. It’s like telling people you can getting remote access to your home windows box by port forwarding the rpd port from your firewall. Eventually it’s going to get hacked.