User Tools

Site Tools


Sidebar

Go Back

Refresh

You are not allowed to add pages

Direct Link

library:centos:sshkey

Gen new ssh key

1. Generate Key

command :

ssh-keygen -t rsa -C "your email" 
use all default configuration

example :

[dev@localhost ~]$ ssh-keygen -t rsa -C "lhs@xinsi.ltd"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/dev/.ssh/id_rsa): 
Created directory '/home/dev/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/dev/.ssh/id_rsa.
Your public key has been saved in /home/dev/.ssh/id_rsa.pub.
The key fingerprint is:

2. Check the key exist

command :

cd .ssh
ls
cat id_rsa.pub

example :

  [dev@localhost ~]$ pwd
  /home/dev
  [dev@localhost ~]$ cd .ssh
  [dev@localhost .ssh]$ ls -al
  total 8
  drwx------. 2 dev dev   38 Nov 15 06:07 .
  drwx------. 6 dev dev  139 Nov 15 06:07 ..
  -rw-------. 1 dev dev 1679 Nov 15 06:07 id_rsa
  -rw-r--r--. 1 dev dev  395 Nov 15 06:07 id_rsa.pub
  [dev@localhost .ssh]$ cat rsa.pub
  cat: rsa.pub: No such file or directory
  [dev@localhost .ssh]$ cat id_rsa.pub
  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCilOM0VMp3YFZNQB1FT/6BZ/dzHSwIVhCS1bHGknYuDy9PK70GBeMTBQzxQMzOnF+cE4XubUwFqzLScq8OPHkQASIYpOXq9aA3ubZwo6TrXPTZTNcxA9G1dyozTaBJ0ispJ6DZgzRc88x0c6b1YCSLg734SERg8susz0YOtK+FG6H5RZX9WiA82NMH1FB9XA1Olr 
 d3sVhzByyVMb3jFeEVssaCxj6dIA7nUff+8ZGR6+48hn7lQJf8oFmVUWW7xTYE/xM/7/QLqyyCTALpBro8y60TzgsEI+ebK9PXmkC51zyMfU50aqr72WoCo8jd9cvPD6ao7iwEVe+v8qQhalCP lhs@xinsi.ltd

3. Add the key to server

command:

cat id_rsa.pub
// show the content,and copy the text,   paste the text to the server.

example:

[dev@localhost .ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCilOM0VMp3YFZNQB1FT/6BZ/dzHSwIVhCS1bHGknYuDy9PK70GBeMTBQzxQMzOnF+cE4XubUwFqzLScq8OPHkQASIYpOXq9aA3ubZwo6TrXPTZTNcxA9G1dyozTaBJ0ispJ6DZgzRc88x0c6b1YCSLg734SERg8susz0YOtK+FG6H5RZX9WiA82NMH1FB9XA1Olrd3sVhzByyVMb3jFeEVssaCxj6dIA7nUff+8ZGR6+48hn7lQJf8oFmVUWW7xTYE/xM/7/QLqyyCTALpBro8y60TzgsEI+ebK9PXmkC51zyMfU50aqr72WoCo8jd9cvPD6ao7iwEVe+v8qQhalCP lhs@xinsi.ltd

4. Check the key to work

Before you set the key:

[dev@localhost proj]$ git clone git@code.aliyun.com:gzxs/meeting.git
Cloning into 'meeting'...
The authenticity of host 'code.aliyun.com (120.55.150.20)' can't be established.
RSA key fingerprint is SHA256:ZrA2ZqYTVyPbw4zytCSAv74ZMaS2LDH74I7sMPtQIG0.
RSA key fingerprint is MD5:69:ab:cb:07:eb:a3:e1:f3:0b:2e:f4:23:b0:c1:c6:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'code.aliyun.com,120.55.150.20' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

After you set the key:

[dev@localhost proj]$ git clone git@code.aliyun.com:gzxs/meeting.git
Cloning into 'meeting'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Total 24 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (24/24), 9.76 KiB | 0 bytes/s, done.
library/centos/sshkey.txt · Last modified: 2022/05/02 00:32 (external edit)