Example One
1, create public key, public key
SSH-KEYGEN-T RSA
Copy the public key to the remote host
Ignore it out of any hint, merry all the way back to the end of it.
2. Copy the public key id_rsa.pub to the/HOME/USERNAME/.SSH directory of the remote machine and name it Authorized_keys
Method 1: One step in place: SCP ~/.ssh/id_rsa.pub Username@hostname:~/.ssh/authorized_keys
Method 2: Copy SCP ~/.ssh/id_rsa.pub username@hostname:~
Login SSH Username@hostname
Append Cat id_rsa.pub >> Ssh/authorized_keys
All kinds of means, as you happy, anyway copy the past on a number of remote host replication ~ If you are the local landing users and remote landing users in line, you can direct SSH hostname direct Landing, the following do not have to see.
3, the resolution of local landing users and remote landing users inconsistent
OK, this thing is very tangled, although do not have to enter the password, but still have ssh username@hostname to login, very uncomfortable, you understand. In fact, the solution is also very simple (but is my colleague told me, face a red), modify the local landing user's ~/.ssh/config file, if the wood has to build a bar, the contents are as follows:
Host hostname
User username
Host hostname2
User UserName2
In this way, the local and remote login user name inconsistency can also be ssh hostname landing.
Example Two
To run a command on a:
# ssh-keygen-t RSA (three consecutive returns, that is, the public and private keys are generated locally, no password is set)
# SSH root@192.168.1.10 "mkdir. SSH" (create. SSH directory on 1.10, you need to enter a password)
# SCP ~/.ssh/id_rsa.pub root@192.168.1.10:.ssh/id_rsa.pub (need to enter password)
The Order on B:
# Touch/root/.ssh/authorized_keys (If this file is already present, skip this one)
# cat/root/.ssh/id_rsa.pub >>/root/.ssh/authorized_keys (append id_rsa.pub content to
In Authorized_keys)
Back to a machine:
# SSH root@192.168.1.10 (no password required, login successful)
Do rsync sync on the B machine without having to enter a password or use a password file.
Rsync-avzu--progress--delete root@192.168.1.9:/var/www//var/www (192.168.1.10 client execution)