Windows上操作
- SSH安装(Win10 自带,没有的话安装Openssh)
- 命令: ssh-keygen 连续回车,在 ~\.ssh 目录下生产id_rsa(私钥),id_rsa.pub(公钥)
- 命令:scp id_rsa.pub root@xxx:/root/.ssh/ 或者手动ftp等方式拷贝也可以
Linux上操作(root用户为例)
- 添加公钥
#: cd ~/.ssh && touch authorized_keys //没有这个文件则创建
#: cat id_ras.pub >> authorized_keys //追加公钥,可以是多个
#: chmod 600 authorized_keys
#: cd .. && chmod 700 .ssh
- 修改ssh配置
#: vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes
#: service sshd restart
Windows上测试
- 单个私钥免登陆
ssh root@xxx.xxx.xxx.xxx
- 多个私钥配置
修改:~/.ssh/config
Host name
HostName xxx.xxx.xxx.xxx
Port 22
User root
IdentityFile ~\\.ssh\\id_rsa
PreferredAuthentications publickey
简化登录: ssh name