1. Generate key
Ssh-keygen " [email protected] "
If you have only a pair of keys, we recommend that you do not modify the default key name, which is always press ENTER
This command generates a pair of keys in your current user's personal directory (for example, my current user is Savokiss, and/home/savokiss/.ssh,root is/root)
The default name is id_rsa and id_rsa.pub
2. Copy the public key
Copy the contents of the id_rsa.pub to your git server (gitlab,coding,github) where the SSH public key is configured
The public key content is similar:
ssh-rsa aaaab3nzac1yc2eaaaabiwaaaqea2czes+h5+dsoa1f2qyocf126le2cfgzcfqll73i+ c61o2vrrrqaqeadelsueuyjrzkonmbn/4zmv7a0zlvipsmsxtkpq+de1rutn/d01nfeolpabsvb0kctgoozvwkxme7wtadzglw8lyc6e/ ooqz71gxbthneh8fh/nbizh2nsbflepeq/yoo8rlodk9wusoyotmqlvah99kob2jm/ dz8g3q36fxovao46nrbp1mdyyjwd7k2xuylqwbewxpxp7plr2vpqyroucxcal9dzrzkwfhhodolpkppdoecn6huimbz/eoomw1wlj+ wtbpwpljqv0rnn2+po3brmucimpw== [email protected]
3. Test the connection
Take coding as an example:
ssh -vt [email protected]
Here,- v is the display of detailed information
A very long message will show you whether the connection is successful, if successful, there will be a successfully!
Hello Savokiss you've connected to Coding.net by SSH successfully!
4. Problems with Linux users
The above test is successful, but I am in '/usr/share/nginx/html ' clone repo unexpectedly still prompt me Permission denied (publickey)
Reason:
I used it all the time Savokiss user, with sudo permissions, and I generated the key without sudo, generated under the '/home/savokiss/.ssh '
But my clone repo directory is '/usr/share/nginx/html ', all belong to root, so I can only add sudo when cloning
That's what sudo causes SSH to automatically go '/root/.ssh ' under the ' Id_rsa ' private key!!!
So I can only use sudo to generate a couple of keys again. O (╯-╰) o
5. Done
The step is so simple that you always have a problem because you always modify its default key name, which causes SSH to fail when reading the default configuration (ID_RSA)
Simply do not change its default name is good!
Of course if you have more than one key to manage, you can change it, and then refer to the following article:
Refer
Multiple SSH Key management tips and Git multi-account login issues (small Huziko)
SSH configuration git clone simple process