First modify the permissions of the PEM file:
sudo chmod 600 key.pem
The command for Mac OS to connect to a server using a PEM file is as follows:
ssh -i key.pem root@IP
You can also use ssh-add to add the key file:
ssh-add -k key.pem
Then just log in normally:
ssh root@IP
In addition, we often experience disconnection issues during use, which can be solved by modifying the following configuration.
Log in to the server:
vim /etc/ssh/sshd_config
Find the following two lines:
ClientAliveInterval 0 ClientAliveCountMax 3
Uncomment and change them to:
ClientAliveInterval 30 ClientAliveCountMax 86400
The meanings of these two lines are:
- 1. The client sends a heartbeat packet to the server every certain number of seconds.
- 2. If the client does not respond within a certain number of seconds, the server automatically disconnects.
Restart the sshd service:
service sshd restart