- Published on
Generating a new SSH key and adding it to remote server
- Authors
- Name
- Arnaud Ferrand
- @arferrand
Generating a new SSH key
- Open Terminal.
- Type the command below, changing your email address
$ ssh-keygen -t rsa -b 4096 -C "you@example.com"
- When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. But take care to avoid overiding existing used keys
Enter file in which to save the key (/Users/you/.ssh/id_rsa):
- At prompt, type twice a secure passphrase, do not forget it:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Generating a new SSH key
- Ensure ssh-agent is enabled:
eval "$(ssh-agent -s)"
Agent pid 84959
- Add your SSH key to the ssh-agent
ssh-add ~/.ssh/id_rsa
Enter passphrase for /Users/you/.ssh/id_rsa:
Identity added: /Users/you/.ssh/id_rsa (/Users/tsamaya/.ssh/id_rsa)
Placing the public key on the remote server
ssh to-the-remote-server
mkdir ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh
touch authorized_keys
chmod 600 authorized_keys
vi authorized_keys
then paste your public key
on your local machine.
edit file ~/.ssh/config
add
Host your-remote-serve-ralias
User you
Hostname your-remote-server-dns-or-ip
IdentityFile ~/.ssh/your-private-key
Other resources
Github has a similar MacOSX, Linux, and Windows help page to generate ssh keys: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/