Writing conventions

$: indicates the server environment

> : indicates the local environment

{Users}: indicates the local user name


: indicates the user name for logging in to the server

The opening

As we all know, there are two types of authentication for logging in to a server, password authentication and certificate authentication. This article introduces certificate verification.

For the most part, we can quickly log in using tools we’ve heard of. Such as:

Windows: Putty, Xshell, SecureCRT, and Finalshell

Mac: Provides terminals, Putty, SecureCRT, and Finalshell

You can choose one or more of them as your daily tools.

The benefits of certificates are not only secure access to the server, but also faster when operating a large number of servers

Local Configuration Certificate

  1. Open the iterm2
  2. Check whether the SSH certificate exists
> cd ~/.ssh
Copy the code

If CD: no such file or directory: /Users/{Users}/. SSH is displayed, you need to configure the SSH certificate

  1. Configure the certificate (skip this step if you already have one)

Enter the following command (email can be filled in arbitrarily) and press Enter three times

> ssh-keygen -t rsa -C "[email protected]"
Copy the code

By default, two files are generated in the ~/. SSH directory: id_rsa(private key) and id_rsa.pub(public key).

Example Modify server SSHD configurations

  1. Edit the configuration file using the vi editor
$ sudo vi /etc/ssh/sshd_config 
Copy the code
  1. Uncomment the content separately
RSAAuthentication yes 
PubkeyAuthentication yes 
AuthorizedKeysFile .ssh/authorized_keys 
Copy the code
  1. Save the configuration File
  2. Restart the SSHD service
$ sudo /sbin/service sshd restart 
Copy the code

Import a public key to a server authentication file and modify its permission

  1. Import the local public key to the server
> ssh-copy-id <Users>@host
Copy the code
  1. You will be prompted to enter the password of the target server
  2. Example Change the permission of related files and directories on the server
$ sudo chmod 700 ~/.ssh 

$ sudo chmod 600 ~/.ssh/authorized_keys
Copy the code
  1. Test success
> ssh '<Users>@host'
Copy the code

Add the server to the iterm2 list

  1. Open the iterm2
  2. Command + PWake up theProfiles
  3. Click on the Edit Profiles
  4. Click + in the lower left corner, fill in the Name field according to your preference, and enter: SSH ‘@host’ in the Command field.
  5. At last,Command + shift + OOpen the search box and type in what you’ve writtenNameQuick access

Enjoy it!