$ ssh-copy-id -h
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
-f: force mode -- copy keys without trying to check if they are already installed
-n: dry run -- no keys are actually copied
-h|-?: print this help
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.1.1'"
and check to make sure that only the key(s) you wanted were added.
如果你重复执行命令的话,会提示你已经添加过了,会出现如下提示,如果你想覆盖,可以使用 -f 参数。
$ ssh-copy-id root@192.168.1.1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
(if you think this is a mistake, you may want to use -f option)
ssh-copy-id 可以把本地的公钥复制到服务器上,这样子就可以不用密码登录了。
使用方法如下:
基本使用
假设服务器的用户名为
root
,地址为192.168.1.1
不指定参数执行
执行以上命令的时候会让你输入服务器密码,输入完后会提示你添加的条数
如果你重复执行命令的话,会提示你已经添加过了,会出现如下提示,如果你想覆盖,可以使用
-f
参数。指定公钥
ssh-copy-id
和ssh
命令类似,可以指定-i
参数,即指定公钥所在位置,使用方法如下前提还是需要用
ssh-keygen
生成公钥私钥文件,如ssh-keygen -f demo