Often log in ali cloud to want to lose that smelly long IP and password, how can such a waste of time let programmers do…..

Aliyun server environment: Ubuntu 16.04.2 Local environment: MacOS 10.12.6


The principle of

The reason is very simple, is to put the local public key on the cloud server

steps

  1. Generate an RSA key on the local computer and press Enter. (Skip this step if you have an RSA key.)
ssh-keygen -t rsa
Copy the code
  1. Obtaining the Local Public Key
cat ~/.ssh/id_rsa.pub
Copy the code
  1. Copy the public key output in the previous step, log in to the cloud server, and perform the following operations on the cloud server
cd~/. SSH/ls // Check whether the authorized_keys file existsCopy the code

If the authorized_keys file is not available, create it in the ~/.ssh/ folder

touch ~/.ssh/authorized_keys
Copy the code
  1. Adds the copied public key content toauthorized_keysAt this time, you can log in to the cloud server on the client without secret
echo "Here is the contents of the copied public key. The double quotation marks cannot be omitted." >> ~/.ssh/authorized_keys
Copy the code
  1. Go back to your client,
SSH [email protected] // The content here is your cloud server IP address, @ is preceded by the user name used to log inCopy the code

But I ran into the following problem: Enter passphrase for key ‘XXXX’ each time I was asked to Enter a password, and then solved it from Stack Overflow by modifying the following contents of the ~/.ssh/config file

Host *
   UseKeychain yes
Copy the code

And a little Cookie

Add the following information to ~/. SSH /config

Host server1
   User root
   HostName 'server1 IP'
Host server2
   User root
   HostName 'server2 IP'
Copy the code

This way, you can directly SSH server1 or SSH Server2 to connect to the corresponding server, without having to remember the IP of each cloud server!

And you’re done!