生成秘钥
ssh-keygen -t [rsa|dsa]
将会生成密钥文件和私钥文件 id_rsa,id_rsa.pub或id_dsa,id_dsa.pub
将 .pub 文件复制到B机器的 .ssh 目录, 并 cat id_dsa.pub >> ~/.ssh/authorized_keys
设置authorized_keys权限
chmod 600 authorized_keys
设置.ssh目录权限
chmod 700 -R .ssh
拷贝秘钥
ssh-copy-id [-i [identity_file]] [user@]machine
ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
例如:
ssh-copy-id -i /root/.ssh/id_rsa.pub -p 2188 root@192.168.3.23
登陆测试
ssh root@192.168.3.23