
上QQ阅读APP看书,第一时间看更新
The public key authorization
The first thing to do is copy your SSH public key from your control machine to the target machine. A full public key infrastructure tutorial is outside the scope of this book, but here is a quick walkthrough on the control node:
$ ssh-keygen -t rsa <<<< generates public-private key pair on the host machine if you have not done so already
$ cat ~/.ssh/id_rsa.pub <<<< copy the content of the output and paste it to the ~/.ssh/authorized_keys file on the target host
You can read more about PKI at https://en.wikipedia.org/wiki/Public_key_infrastructure.
Because we are using key-based authentication, we can turn off password-based authentication on the remote node and be more secure. You will now be able to ssh from the control node to the remote node using the private key without being prompted for a password.
Can you automate the initial public key copying? It is possible, but is highly dependent on your use case, regulation, and environment. It is comparable to the initial console setup for network gears to establish initial IP reachability. Do you automate this? Why or why not?