【Linux】ssh-copy-id三步实现ssh免密登陆
一、本地机器上使用ssh-keygen产生公钥私钥对###
ssh-keygen -t rsa -C "XXXX@163.com" --->执行完会在~/.ssh/下生成公钥私钥对
查看公钥私钥对:
wucaiyundeMacBook-Pro:~ wucaiyun$ cd ~/.ssh/
wucaiyundeMacBook-Pro:.ssh wucaiyun$ ll
total 24
899401 0 drwx------ 5 wucaiyun staff 160 12 18 15:59 ./
686353 0 drwxr-xr-x+ 31 wucaiyun staff 992 12 19 16:42 ../
908256 8 -rw------- 1 wucaiyun staff 1823 12 5 23:25 id_rsa
908257 8 -rw-r--r-- 1 wucaiyun staff 399 12 5 23:25 id_rsa.pub
1745218 8 -rw-r--r-- 1 wucaiyun staff 350 12 19 17:13 known_hosts
二、用ssh-copy-id将公钥复制到远程欲登陆机器中###
ssh-copy-id -i .ssh/id_rsa.pub username@192.168.x.xxx
注意: ssh-copy-id 将key写到远程机器的 ~/ .ssh/authorized_key.文件中
三、ssh免密登陆###
wucaiyundeMacBook-Pro:~ wucaiyun$ ssh username@1xx.xx.xxx.xxx
Welcome to Alibaba Cloud Elastic Compute Service !