一、客户机生成ssh公钥密钥对 1、生成公钥密钥
[root@server ~]# ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair. #提示正在生成rsa密钥对
Enter file in which to save the key (/home/usrname/.ssh/id_dsa): #询问公钥和私钥存放的位置,回车用默认位置即可
Enter passphrase (empty for no passphrase): #询问输入私钥密语,输入密语
Enter same passphrase again: #再次提示输入密语确认
Your identification has been saved in /home/usrname/.ssh/id_dsa. #提示公钥和私钥已经存放在/root/.ssh/目录下
Your public key has been saved in /home/usrname/.ssh/id_dsa.pub.
The key fingerprint is: x6:68:xx:93:98:8x:87:95:7x:2x:4x:x9:81:xx:56:94 root@server #提示key的指纹
2、查看公钥
➜ .ssh cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDps5+BCLcaBtph9viIjGwDhphHwSvhj5Lq/Y2K/TR8yZrYqViNfXX9XnaF63jwj5z1ym8QSx6J9l2DSqxF9msroHuv30S4c2LGl4BWl2hCT5zF1GtHB6Q1iJU0yxm9J/261eR7YpiwIa5pn+ZSfBn9SXqOPT5ARNg81Ec0h9//6p3jd0wbEh2D07OrxQcwC1LANHwXwV0PrBKg1RcmNzE8PzWLhwfuEWJE/QbVVRINgvJ2YWPeV+X0r4JJF+XDeQfAeuIx8D6c6UVeG+3w9n8xjvoLMvp0fSsP034cyjv/QK0yYN73xMc7Omm3CcobvWwk2vcSiv+OujNkJzTNKLyn wanghua.zhou@ele.me
3、复制公钥-用来传输到服务器:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
二、登录被管理服务器创建.ssh文件 1、登录被管理服务器,在当前用户的家目录创建.ssh目录(/home/hero/.ssh),并赋予700权限
mkdir -m 700 .ssh
2、退出本机环境,使用scp把authorized_keys传输到服务器上的.ssh目录
scp ~/.ssh/authorized_keys wanghua.zhou@vpca-base-alliance-1.vm.elenet.me:.ssh
备注: 1、最好是给authorized_keys赋予600的权限