SSH keys are a way to identify trusted computers, without involving passwords. Most git servers choose SSH keys to authorize clients.
Check for SSH keys
check for existing SSH keys on your computer.
$ ls -al ~/.ssh# Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:
- id_rsa.pub
- id_dsa.pub
Generate a new SSH key
1) Creates a new ssh key, using the provided email as a label
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
2) We strongly suggest keeping the default settings as they are, so when you‘re prompted to "Enter a file in which to save the key", just press Enter to continue.
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
3) We strongly recommend a very good, secure passphrase.
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
4) After you enter a passphrase, review the fingerprint, or id, of your SSH key.
Add the New SSH Key to Server
Add the content of id_dsa.pub to the end of sever’s authorized_keys
echo ‘the content of id_dsa.pub’ >> ~/.ssh/authorized_keys
Configure SSH Client
Edit ssh configuration file ‘~/.ssh/config’.
Host servername HostName 192.168.3.1 User Admin IdentityFile ~/.ssh/id_rsa CompressionLevel 6
Now you can test the ssh connection
ssh servername
时间: 2024-11-02 18:34:51