How to Connect to a Remote Server with SSH on Mac
To connect to a Remote Server with SSH on Mac, open Terminal by navigating to Applications > Utilities, double-clicking on the Terminal app, and then enter the SSH command: ssh username@remote_server_ip
.
SSH is a common and secure way to connect to a remote Linux server in Linux, Mac, or Windows devices, so if you use a Linux server, ensure that it is equipped with an SSH tool.
Prerequisite to connect to remote server on Mac
- Linux VPS accessible via SSH
- Remote server details (server’s IP address or domain name, your login username and password on the server, or SSH keys).
- Necessary permissions to log in via SSH.(typically administrator)
- SSH port if the server uses a different port (SSH uses port 22 by default.)
How to SSH into a server using Terminal in Mac
Since SSH is a built-in client within the Mac Terminal application, you can use its Terminal for basic SSH functionality without needing any additional software. Here is a guide to connect to a remote server with SSH on Mac:
1. Open Terminal:
There are two ways to find and open the Terminal app on Mac:
- Go to spotlight search by pressing Cmd + Space on the keyboard, type terminal in the search box, and select Terminal.app.
- Go to Applications > Utilities and double-click on the Terminal app to open the Terminal on Mac.
2. Connect to a remote server using SSH command:
Run the basic SSH command to connect to the remote server on Mac:
ssh username@remote_server_ip
Replace “username” with your username on the remote server and “remote_server_ip” with the IP address of the remote server. Press Enter.
Connect to a remote server by specifying SSH port
If a different SSH port is set on a remote server, you will need to specify the SSH port in the SSH command:
ssh username@remote_server_ip -p port_number
Connect to a remote server via an SSH Key
If you have set up SSH keys for more secure passwordless authentication, you can connect to the server using the SSH key:
ssh -i key.file username@remote_server_ip
Connect to a remote server in Verbose Mode
To get additional information about the connection process, you can connect to a remote server with SSH in verbose mode, which is a helpful way to troubleshoot any issues:
ssh -v username@server_address
3. Verify the server’s authenticity
If this is the first time you are connecting to a remote server, the terminal prompts you to confirm the server’s authenticity by displaying the server’s fingerprint messages. This will ask you whether you trust this server and whether you are sure to connect to it. If you trust, type “yes” to proceed.
4. Enter Your Password
The terminal will prompt you to enter your password for the remote server. Type your password and hit Enter again.
Note: You won’t see the password characters on the screen for security reasons.
Once authenticated and everything is entered correctly, you will be logged in to the remote server successfully, and a command prompt will be displayed indicating that you are connected to the remote server.
Quick guide to connect to a remote server over SSH on Mac via SSH client
You can download third-party clients on Mac if you prefer a GUI SSH client for managing SSH connections.
As we previously introduced GUI SSH clients for Linux and Windows, Several third-party SSH clients for Mac manage SSH connections.
Some popular options include Termius, OpenSSH, Transmit, and others that handle SSH connections easier than the command line.
The steps to connect to a remote server with an SSH client (Temius app) on a macOS device are as follows:
1. Launch the app store on your Mac device and search for Termius to download it.
2. Launch the Termius app, sign in using your email, and choose its free version.
3. Select the “NEW HOST” option from the top menu and then enter your server’s IP address, port, username, and password in the related fields.
4. To save your server details, click on the check mark at the top of the screen.
5. Double-click the newly added server and select the “Continue” option.
You will connect to the remote server successfully.
Manage remote server after connecting with SSH
After connecting to the remote server, you can perform your administration tasks remotely, and we can assist you in this regard.
SSH Syntax
SSH Syntax is as follow:
ssh
End SSH connection
After performing your task, you may need to end the SSH session, to log out of the SSH session you need to enter “exit” in terminal and press the Enter:
exit
Sample output:
logout
Connection to xx.xxx.xxx.xx closed.
So, the shell prompt returns to the local machine’s terminal and workstation, and you will disconnect from a remote server.
Run Commands remotely on your server Over SSH
One advantage of connecting to the server through SSH is executing commands remotely in the local terminal window without leaving the local shell environment.
To run a single command on your remote server with SSH, use the following format:
ssh [username]@[ip-address] [command]
To run multiple commands on your remote server with SSH, use the following format:
ssh [username]@[ip-address] "[command 1]; [command 2]; [command 3]"
Replace “username” with your username on the remote server and “ip-address” with the IP address of the remote server, and [command] with the command you want to run.
Note: When you run several commands, be careful to separate them using semi-colon (;), and double quotation marks are also necessary.
Conclusion
Now, you should be able to use SSH to connect to a remote server on Mac, which is the best way to secure connections between local machines and remote servers, administer remote servers, transfer files, develop software, and execute commands.