Generate a new SSH key

Posted by flow is me on 2015-06-29

###1. Check for SSH keys.

1
$ cd ~/.ssh

If it says “No such file or directory“ skip to step 3. Otherwise continue to step 2.

###2. Backup and remove existing SSH keys.
Since there is already an SSH directory you’ll want to back the old one up and remove it:

1
2
3
4
5
$ lsLists all the subdirectories in the current directory
config id_rsa id_rsa.pub known_hosts
$ mkdir key_backupmakes a subdirectory called "key_backup" in the current directory
$ cp id_rsa* key_backupCopies the id_rsa and id_rsa.pub files into key_backup
$ rm id_rsa*

###3. Generate a new SSH key.
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

1
2
3
4
$ ssh-keygen -t rsa -C "ldneedu@gmail.com"
Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<press enter>

Now you need to enter a passphrase.

1
2
Enter passphrase (empty for no passphrase):<enter a passphrase>
Enter same passphrase again:<enter passphrase again>