Make writing a habit together! This is the 8th day of my participation in the “Gold Digging Day New Plan · April More Text Challenge”. Click here for more details.

preface

SSH Config Indicates the basic format of the configuration file

HostName: is the Host name of the target Host, which is usually followed by the address name when using SSH. Port: indicates the specified Port number. User: specifies the login User name. IdentifyFile: specifies the private key address.Copy the code

Mac using ~ /. SSH config configuration making SSH keys: https://kunnan.blog.csdn.net/article/details/78234772

I Use the SSH config file to manage SSH connections

1.1 example

# Private 192.168.2.125
Host iPhone
HostName  192.168.2.125
User root 
IdentityFile ~/.ssh/id_rsa_Theos125

# Private gitlab.v6h5.
Host gitlab.v6h5.cn
HostName  gitlab.v6h5.
User git
IdentityFile ~/.ssh/id_rsa_qinbaowan
Copy the code

1.2 Precautions

  • ‘Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

`

$SSH iPhone [email protected]'s password: iPhone:~ root#Copy the code
  • Passes the public key to the remote hostSsh-copy-id Specifies the authentication file
SSH - copy - id - I id_rsa_Theos125 [email protected]Copy the code

II Permission Settings for private key files

Permissions 0640 for ‘/Users/ MAC /.ssh/ qctMAC_id_RSA ‘are too open.

This file cannot be accessed by others, simply by revoking the read permissions of the group and others.

➜. SSH chmod 600 qctmac_id_rsa ➜. SSH chmod 644 qctmac_ID_rsa. pub -rw-r--r--@ 1 MAC staff 742 4 7 18:03 qctmac_id_rsa.pub -rw-------@ 1 mac staff 3434 4 7 18:03 qctmac_id_rsaCopy the code

III Prior knowledge: SSH connection without password

  1. Create rsa: ssh-keygen -t rsa -b 4096 -c “[email protected]

  2. SSH touch config: ➜

  3. Run pbcopy or ssh-copy-id to copy the public key to the corresponding remote server

➜. SSH pbcopy < ~/. SSH /qctmac_id_rsa.pub

Run the ssh-copy-id command to report data

Ssh-copy-id: never leak your private key! Just copy the public key (*.pub file) to the remote server;

‘$ssh-copy-id -i ~/. SSH /id_rsa_Theos125 [email protected]

‘(IP+ default port) Ssh-copy-id will find the public key if the private key is specified.

If the configuration is on the company Mac, set the password and remove xx_id_rsa/xx_id_rsa.pub in the ~ /. SSH/directory when replacing the Mac.

Kunnan.blog.csdn.net/article/det…

3.1 create rsa

ssh-keygen -t rsa -b 4096 -C "[email protected]"

3.2 Configuring SSH Config

Syntax of the config file

Host alias HostName: is the Host name of the target Host, which is usually followed by the address name of SSH. Port: indicates the specified Port number. User: specifies the login User name. IdentifyFile: specifies the private key address.Copy the code
# Private 192.168.2.125
Host iphone
HostName  192.168.2.125
User root 
IdentityFile ~/.ssh/id_rsa_Theos125

# Private github
Host github.com
HostName  github.com
User git
IdentityFile ~/.ssh/id_rsa

# git clone [email protected]:u011018979/resume.git

Host codechina.csdn.net
HostName  codechina.csdn.net
User git
IdentityFile ~/.ssh/qctmac_id_rsa

Copy the code

3.3 Testing the Connection

➜  csdn ssh -T [email protected]       
Enter passphrase for key '/Users/mac/.ssh/qctmac_id_rsa': 
Welcome to GitLab, @u011018979!


Copy the code

Connect the iPhone

$SSH iPhone [email protected]'s password: iPhone:~ root#Copy the code

3.4 Example: Configuring GitHub SSH Keys

Enter ls -al ~/.ssh to see if existing SSH keys are present:

If you don’t have an existing public and private key pair, or don’t wish to use any that are available to connect to GitHub, then generate a new SSH key.

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Add the corresponding public key to the corresponding remote server. SSH pbcopy < ~/. SSH /qctmac_id_rsa.pub

Git config –global –edit

Modify author: git commit –amend –reset-author

The effect

see also

SSH Principle and Application (1) : Remote login