Every time you log in to the server, you have to enter your password. “Lazy people are the driving force of social progress”, my aim is to do not manual can be automatic. Here is how to create a password free login server:

1. Generate public keys and keys

Git’s public and private key configuration is also generated locally, so I won’t repeat it here.

2. Edit the SSH configuration file

Vim ~/. SSH /config adds:#Tencent ServerHost TS HostName Server IP address User root PreferredAuthentications publickey IdentityFile ~/. SSH /id_rsa_tencent_server 1. Host Ts # alias, 2. HostName server IP address # complete domain name or IP address 3. User root # PreferredAuthentications publickey # Priority Authentication type SSH 5. IdentityFile ~/. SSH /id_rsa_tencent_server # Path to the local private key fileCopy the code

See the following figure for detailed configuration:

My computer is configured with the company’s GitLab and Github, plus the server, there are three groups of configurations.

3. Place the public key in the server directory

scp ~/.ssh/id_rsa_tencent_server.pub ts:~/.ssh/
Copy the code

4. Configure the public key for the server

mv id_rsa.pub authorized_keys
Copy the code

If the server has authorized_keys, the file will be overwritten.

5. Local and server file permissions

SSH chmod 600 ~/. SSH /id_rsa_tencent_server Set file permissions on the server:  chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keysCopy the code

6. Disable password login on the server (optional)

vi /etc/ssh/sshd_config 

#Set PasswordAuthentication to no,
#Then restart service SSHD restartIf you need to log in with a password, this step can be omitted (SSH [email protected])Copy the code

7. Log in to the server

ssh ts
Copy the code

8. Gifs

The following gifs illustrate two ways to log in to the server:

  • SSH user @ IP
  • SSH User-defined name

The first method requires you to manually enter your password each time and re-enter it if you make a mistake, which is very inconvenient. The second method, however, eliminates the need to enter your password every time, reducing the risk of mis-typing. It is not difficult to find that the second way is convenient and fast, once and for all, and it is highly recommended to operate the configuration.

8. Refer to tutorials

  • Bitzhi.com/2015/07/log…
  • My.oschina.net/kmwzjs/blog…
  • Cssor.com/mac-ssh-aut…

Welcome to 😁