SSH (Secure Shell) is a protocol that allows secure connections between systems. macOS includes a built-in SSH client that you can use from the Terminal to connect to remote servers.
Step 1: Open the Terminal
To start an SSH connection, you will need to use the Terminal app:
- Open Finder
- Go to Applications Utilities
- Double-click on Terminal
You can also use Spotlight (⌘ + Space) and type "Terminal" to find it quickly.
Step 2: Connect to the Server
The basic command to connect via SSH is:
ssh root@server-ip-address -p 22
Note: If the server uses the standard port (22 TCP), you can omit the -p parameter:
ssh root@server-ip-address
Step 3: Authentication
When running the SSH command, one of these situations will occur:
Password Authentication
If it's your first time connecting to the server, you'll see a message like this:
The authenticity of host 'X-X-X.clouding.host (79.X.X.X)' can't be established.RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes and press Enter. Then enter your password when prompted.
SSH Key Authentication
If you've set up SSH key authentication, the process will be automatic. If you need to specify a different private key than the default, use:
ssh -i /path/to/your/private_key root@server-ip-address
Important: Private keys must have restrictive permissions. Use this command to ensure that:
chmod 600 /path/to/your/private_key
Step 4: Work in the Remote Session
Once connected, you can run commands on the remote server as if you were working locally. The prompt will change to indicate that you're on the remote machine.
Step 5: Close the Connection
To disconnect from the remote server, simply type:
exit
or press Ctrl + D.
Advanced Tips
Set Up Aliases for Frequent Connections
You can add aliases in your ~/.ssh/config file to simplify frequent connections:
Host my-server
HostName server-ip-address
User root
Port 22
IdentityFile ~/.ssh/my_private_key
Then you can connect simply by typing:
ssh my-server
Transfer Files with SCP
From macOS, you can also use SCP (based on SSH) to transfer files:
scp local_file root@server-ip-address:/remote/path
To copy from the server to your Mac:
scp root@server-ip-address:/remote/path/file /local/path
Use Persistent SSH Connections
To prevent disconnections during long sessions, add this to your ~/.ssh/config:
Host * ServerAliveInterval 60 ServerAliveCountMax 5
Troubleshooting
- Connection refused: Check that the server is accessible and the port is correct.
- Authentication failed: Review your username and password, or your SSH key configuration.
- Key issues: If you changed the server keys, delete the corresponding entry in ~/.ssh/known_hosts.
With these steps, you should be able to connect to remote servers without any issues from your Mac using SSH.
We hope this article has helped you. If you have any questions about this or any other matter related to your servers on Clouding, write to us at support@clouding.io. We're here to help! 😉