Github: авторизация по SSH ключам

 

github_logoГенерируем ключ:

$ cd ~/.ssh/
$ ssh-keygen -t rsa -C "username@domain.tld"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/setevoy/.ssh/id_rsa): setevoy_github_openssh
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in setevoy_github_openssh.
Your public key has been saved in setevoy_github_openssh.pub.
The key fingerprint is:
1b:d3:13:10:52:5f:31:80:98:c9:82:94:1f:7c:79:64 username@domain.tld
The key's randomart image is:
+--[ RSA 2048]----+
| ..+ ..BEo..+.   |
|  o + Booo . .   |
|   . + .  o      |
|    .    . .     |
|        S o      |
|         + .     |
|        .        |
|                 |
|                 |
+-----------------+

Проверяем:

$ ls -l | grep github
-rw------- 1 setevoy setevoy  1679 тра 31 11:18 setevoy_github_openssh
-rw-r--r-- 1 setevoy setevoy   407 тра 31 11:18 setevoy_github_openssh.pub

Проверяем доступ сейчас:

$ ssh -T git@github.com
Permission denied (publickey).

Переходим в настройки аккаунта:

github_ssh_1

Переходим в SSH and GPG keys:

github_ssh_2

Жмём New SSH key  и добавляем ключ:

$ cat setevoy_github_openssh.pub 
ssh-rsa AAAAB***wpBDlz username@domain.tld

github_ssh_3

Вводим пароль – и ключ добавлен:

github_ssh_4

Проверяем.

$ ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

И ещё раз – клонируем репозиторий:

$ git clone git@github.com:project/project_house.git
Cloning into 'project_house'...
Warning: Permanently added the RSA host key for IP address '192.***.***.130' to the list of known hosts.
remote: Counting objects: 249, done.
remote: Compressing objects: 100% (203/203), done.
remote: Total 249 (delta 41), reused 249 (delta 41), pack-reused 0
Receiving objects: 100% (249/249), 6.26 MiB | 3.08 MiB/s, done.
Resolving deltas: 100% (41/41), done.
Checking connectivity... done.

Создаём бранч:

$ git checkout -b develop
Switched to a new branch 'develop'

И пушим его обратно:

$ git push -u origin develop
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:project/project_house.git
 * [new branch]      develop -> develop
Branch develop set up to track remote branch develop from origin.

Готово.