Creating SSH keys on CentOS
The chances are that you already have an SSH key pair on your CentOS client machine. If you are generating a new key pair, the old one will be overwritten.
Run the following ls command to check whether the key files exist:
[root@oracle-db-19c ~]# ls -l ~/.ssh/id_*.pub
ls: cannot access '/root/.ssh/id_*.pub': No such file or directory
[root@oracle-db-19c ~]#
If the output of the command returns something like No such file or directory
, or no matches found
it means that the user does not have SSH keys, and you can proceed with the next step and generate SSH key pair.
Otherwise, if you have an SSH key pair, you can either use those or backup up the old keys and generate new ones.
[root@oracle-db-19c ~]# git config --global user.name "psmaxwell"
[root@oracle-db-19c ~]# git config --global user.email "xxxxxxxxxxx@qq.com"
[root@oracle-db-19c golang_projects]#
[root@oracle-db-19c golang_projects]# git version
git version 2.39.0
[root@oracle-db-19c golang_projects]# git config --list
user.name=psmaxwell
user.email=xxxxxxxxxxxxx@qq.com
init.defaultbranch=main
safe.directory=/home/maxwell/projects/golang_projects
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[root@oracle-db-19c golang_projects]# ssh-keygen -t rsa -C "xxxxxxxxxxxxx@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Passphrases do not match. Try again.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:DHZt+qho/u0LlfWkBCeok50h+/S8xN1dzx6nOxlbXUw xxxxxxxxxxxxxxxx@qq.com
The key's randomart image is:'
+---[RSA 3072]----+
| .o . |
| . o = E|
| *oo. = . o |
| =.++ * + +|
| + +S..... o+|
| ..=o. . o.*|
| ..... Bo|
| .. +. = .|
| oo.o.+. .o |
+----[SHA256]-----+
[root@oracle-db-19c golang_projects]# cd /root/.ssh/
[root@oracle-db-19c .ssh]# ls -ltr
total 8
-rw-------. 1 root root 2655 Jan 15 17:32 id_rsa
-rw-r--r--. 1 root root 570 Jan 15 17:32 id_rsa.pub
[root@oracle-db-19c .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC9yxcBz9gGBTh/lNRI42wbD7AqdGI3bWdh25SIKhYZVTe4TKoMtx2cWsQPLTp7R98Wf6obIRCtA5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxQ7lXPHKaTG9Qi8vEg6FY5LgQULr6AKLQSRdksS05rHYZNhs5ZsHVgDsyMlSiA8LA54iHJYuPohcsyxj4IdnRWij5kjYuNmZM9HuAkvO4zOZD5wR4jCaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxojFgeD+DrVPlvW9K5QL+LPWA7YMIhPw33OPpDsKDWoGROiazKGx6nzEaty1pw6YoxOmvlCk= xxxxxxxxxxxxxxxxxx@qq.com
[root@oracle-db-19c .ssh]#
[root@oracle-db-19c maxwell]# cd projects/
[root@oracle-db-19c projects]# ls -ltr
total 0
drwxrwxr-x. 4 maxwell maxwell 70 Jan 15 16:48 golang_projects
[root@oracle-db-19c projects]# cd golang_projects/
[root@oracle-db-19c golang_projects]# ls -ltr
total 4
drwxrwxr-x. 16 maxwell maxwell 4096 Jan 15 14:44 maxwell_the_go_programming_language_projects
[root@oracle-db-19c golang_projects]# git clone git@github.com:psmaxwell/awesome_golang_project1_the_go_programming_language.git
Cloning into 'awesome_golang_project1_the_go_programming_language'...
Enter passphrase for key '/root/.ssh/id_rsa':
warning: You appear to have cloned an empty repository.
[root@oracle-db-19c golang_projects]# ls -ltr
total 4
drwxrwxr-x. 16 maxwell maxwell 4096 Jan 15 14:44 maxwell_the_go_programming_language_projects
drwxr-xr-x. 3 root root 18 Jan 15 17:36 awesome_golang_project1_the_go_programming_language
[root@oracle-db-19c golang_projects]#