|
1. Create a public local machine
Open the universal terminal, execute the following command, ignore all output, all the way to happily enter.
ssh-keygen -t rsa -C 'your email@domain.com'
-t Specifies the key type, the default that is rsa, may be omitted
-C Comment text settings, such as your e-mail
2. Copy the public key to the ssh server
The public ~ / id_rsa.pub file generated by the previous step, copied to the ssh server corresponding to the user under the ~ / .ssh / authorized_keys file, you can have a variety of ways, here only three commonly used.
[For osx system] use ssh-copy-id-for-OSX tool to copy the public key to the ssh server
brew install ssh-copy-id
ssh-copy-id username @ hostname # username and hostname will be replaced by your ssh server user name and IP
Use this mode when the user directory under ssh server username yet .ssh directory
cat ~ / .ssh / id_rsa.pub | ssh username @ hostname "mkdir ~ / .ssh; cat >> ~ / .ssh / authorized_keys"
General Information
scp ~ / .ssh / id_rsa.pub username @ hostname: ~ / # to copy the public key file to the ssh server
ssh username @ hostname # username and password to log in to the ssh server
mkdir .ssh # If the .ssh directory already exists, this step can be omitted
cat id_rsa.pub >> .ssh / authorized_keys # public key file id_rsa.pub file content is appended to the authorized_keys file
3. Quick Login
After completing the above steps, you can use the following command to log ssh server, my mother no longer have to worry about you can not remember your password
ssh username @ hostname # username will replace your ssh server user name, hostname replace server ip
However, each still need to enter ssh username @ hostname, still not really the best solution, if you can achieve a key or a login command to log the best, however, let's look at all those solutions
ssh itself also provides a quick way to solve this problem, to the ~ / .ssh / config configuration file to add the information to your ssh server
vim ~ / .ssh / config # Without this file, you can direct new
Add the contents of the file format is as follows:
Host alias # custom aliases
HostName hostname # replace your ssh server ip or domain
Port port #ssh server port, default is 22
User user #ssh server user name
Private key file IdentityFile ~ / .ssh / id_rsa # The first step of generating a public key corresponding to the file
After you save the file exit, you can use an alias to log ssh server
ssh alias #alias alias you in ~ / .ssh / config configuration file
If you need to configure multiple ssh account, as long as ~ / .ssh / config blank lines to write, as follows:
Host foo
HostName 192.168.2.222
Port 22
User test
IdentityFile ~ / .ssh / id_rsa
Host alias
HostName hostname
Port port
User user
If you are using a local terminal zsh, it would be too simple, however, and directly to zsh add an alias
echo "alias ssh-to-username = 'ssh username @ hostname'" >> ~ / .zshrc # will be replaced by your username and hostname of the server information
source ~ / .zshrc # reload zshrc changed files
ssh-to-username # using aliases, a command to log in to your ssh server
If you are using a local terminal iterm2 Profile can also be added to achieve a key log on, skip specific steps here |
|
|
|