Run the following command to create ~/.ssh
folder if it doesn't already exist and set the right access permission.
{ { { mkdir ~/.ssh && echo "No ~/.ssh found so just created" } || { echo "~/.ssh already exists"; false } } ; chmod 700 ~/.ssh }
Once done, please check if you have the folder with the right access permission.
ls -ld ~/.ssh
should show you something like
drwx------ 14 username group 448 27 Sep 15:19 /Users/username/.ssh
Check it has rwx
and /Users/YOUR_USERNAME/.ssh
.
$ curl -Lo- https://goo.gl/7XCEtt | bash
The script works well only for Mac OSX (for now).
In your ~/.bashrc
or ~/.zshrc
, add the following alias so that you can easily use it.
alias simple-ssh-keygen='~/path/to/script/simple-ssh-keygen.sh'
- Run the following command
$ simple-ssh-keygen "your.email@address.com"
# The filename will be id_KEY-TYPE
# e.g.) id_rsa or id_ed25519
Or
$ simple-ssh-keygen "your.email@address.com" "your-private-key-file-name"
# The filename will be your-private-key-file-name_KEY-TYPE
# e.g.) my-github-key => my-github-key_ed25519 / my-github-key_rsa
- Then select the key type (
ed25519
is recommended, and GitHub supports it but BitBucket doesn't.)
Please select the key type.
[0] ed25519
[1] rsa
[x] Exit
- Once it's done, your public key's copied to the clipboard which means you can simply paste it into GitHub's public key input filed by Cmd+V.
- Then add the following lines to
~/.ssh/config
(create this file if it doesn't exist yet).
Host hostname-to-be-used
Hostname the-actual-hostname
Port port-number (optional)
IdentityFile your-private-key-file-path
e.g.) If it's GitHub,
Host github.com
Hostname github.com
Port 22
IdentityFile ~/.ssh/your-github-private-key-file-name
e.g.) If it's GitLab
Host gitlab.com
Hostname gitlab.com
Port 22
IdentityFile ~/.ssh/your-gitlab-private-key-file-name
e.g.) If you have multiple accounts on GitHub (one of which is for machine account for instance),
Host github.com
Hostname github.com
Port 22
IdentityFile ~/.ssh/your-github-private-key-file-name
Host github-ci.com
Hostname github.com
Port 22
IdentityFile ~/.ssh/your-github-ci-private-key-file-name
So when you clone a repository as yourself, it is
git clone git@github.com:your-username/repo-name.git
If it's the machine account for CI which is the second one,
git clone git@github-ci.com:your-username/repo-name.git
Please read this setup guide.