What are the ways to connect Mac to remote server?

Mac uses Shell (terminal) ssh to connect to the remote server

Students who use Mac for remote maintenance for the first time may find various ssh software available on Mac on the Internet, but you may not know that Mac comes with a remote connection tool! .
Here are two methods:

1. Method 1: Connect directly with the command line

Step 1: Open Terminal on Mac

Step 2: Enter in the terminal ssh -p 端口号 服务器用户名@ip (such as ssh -p 22  [email protected] ) and press Enter, you may be asked to enter yes or no to confirm whether to connect, enter yes and press Enter, and then you will be asked to enter the user password.

Step 3: Enter the user password of the remote server.

2. Method 2: Connect with shell

Step 1: Open Terminal on Mac

Step 2: Select New Remote Connection in the Shell menu of the terminal, or right-click the terminal icon in the dock and select New Remote Connection

Step 3: When you click on the new remote connection, a pop-up box will appear, select Secure Shell (ssh) and click the plus sign under the server on the right

Step 4: Then enter the name or IP address of the remote connected server in the input box, and click OK

Step 5: You can see the server you just added in the server of Secure Shell (ssh), select it! Add the user name of the remote server in the user input box, and click Connect!

Step 6: The terminal will pop up a new window, you can enter the user password of the remote server!

3. Method 3: Connect with a key

  1. Open the Terminal application: You can type "terminal" into Spotlight search, or find it in the Utilities folder under the Applications folder.

  2. Confirm that you have generated SSH keys and know where your private and public keys are stored. If you haven't generated SSH keys yet, see the SSH key generation tutorial. Typically, private keys are stored in ~/.ssh/id_rsafiles and public keys are stored in files. ~/.ssh/id_rsa.pub

  3. In a terminal, use ssh-addthe command to add your private key to the SSH agent. If your private key is stored in the default location, you can simply run the following command:

ssh-add

If your private key is stored elsewhere, use -Kthe option to specify the path to the private key file. For example:

ssh-add -K ~/.ssh/my_private_key

    4. Connect to the remote host using SSH. In a terminal, use sshthe command, specifying your username and the IP address or domain name of the remote host. For example:

ssh username@remote_host

If your SSH server uses a port other than the default, use -pthe option to specify the port number. For example:

ssh -p 2222 username@remote_host

  5. If your SSH keys are properly configured, you will be able to connect to the remote host without entering a password.

Hope these steps help you successfully connect to the remote host!

Guess you like

Origin blog.csdn.net/qq_24518001/article/details/130026086