simplify ssh key authorization using ssh-copy-id

Pre

Using ssh to login remote machine is a very common operation, but if you are tierd of being prompted for pass-phrases, you can use authorization key.

Issue

copy your public key under(usually it’s in ~/.ssh/id_rsa.pub), and append it to the target machine’s ~/.ssh/authorized_keys file, then the prompt for pass-phrases won’t block you.
but the operation can be very unconvinient, you have to copy it into your system clipboard and login target first to paste into the file. Especially when you are working on a pure tty, you don’t really have a system-wild clipboard to do the operation between local and the target machine, but you could still use tools like tmux to achieve it, they have a shared clipboard to sync everything across terminals.

Solution

I used to use tmux to do it until I found the ssh-copy-id. it can easily do the copy automatically.

Steps

you can add it to the authorized_keys to avoid being repeatedly prompted for pass-phrases
ssh-copy-id root@192.168.199.240

note that you should operate on the current, not the remote target machine.

tip: ssh-copy-id will use default_ID_file, basically it won’t have any problems, but if you have multiple public key files that matches id*.pub in your ~/.ssh/, the key being used may not the one you want, solve it refering to the following:

The default_ID_file is the most recent file that matches: ~/.ssh/id*.pub, (excluding those that match ~/.ssh/*-cert.pub) so if you create a key that is not the one you want ssh-copy-id to use, just use touch(1) on your preferred key’s .pub file to reinstate it as the most recent.