It's up to you whether you want to use a passphrase The entire key generation process looks like this:
ssh-keygen-trsaGeneratingpublic/privatersakeypair.Enterfileinwhichtosavethekey (/Users/tony/.ssh/id_rsa): Enterpassphrase (empty fornopassphrase): Entersamepassphraseagain:Youridentificationhasbeensavedin/Users/tony/.ssh/id_rsa.Yourpublickeyhasbeensavedin/Users/tony/.ssh/id_rsa.pub.Thekeyfingerprintis:4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67tony@Antonios-MacBook-Pro.localThekey's randomart image is:+--[ RSA 2048]----+| .oo. || . o.E || + . o || . = = . || = S = . || o + = + || . o + o . || . o || |+-----------------+
The public key is now located in /Users/tony/.ssh/id_rsa.pub
The private key (identification) is now located in /Users/tony/.ssh/id_rsa
Add your SSH key to the ssh-agent
Run the following commands to make sure that the ssh-agentis running.
If you're running macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain:
No matter what operating system version you run you need to run this command to complete this step:
Host Key Warning
If you happened to destroy a server directly prior to creating the one that you are connecting to, you may see a message like this:
If this is the case, your new server probably has the same IP address as the old, destroyed server, but a different host SSH key. This is fine, and you can remove the warning, by deleting the old server's host key from your system, by running this command:
Now try connecting to your server again.
SSH Best Practices
When you set up SSH, you create a key pair that contains a private key (saved to your local computer) and a public key (uploaded to a remote server). This server uses the key pair to authenticate anything the associated account can access. This two-way mechanism prevents man-in-the-middle attacks.
This first key pair just created is your default SSH identity. I suggest to use it to manage your servers. If you need to manage GitHub or BitBucket accounts you need more than a default identity, you can set up additional keys.
For security reasons, we recommend that you generate a new SSH key and replace the existing key on your account at least once a year.
ssh-add -K ~/.ssh/id_rsa
# you can check your added key with:
ssh-add -l
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
...