ssh-copy-id使用哪个密钥

我看了下~/.ssh/目录,里面有两个密钥文件:id_ed25519.pub id_rsa.pub,ssh-copy-id向远程服务器拷贝密钥时,会拷贝哪一个?还是都拷贝?

后续使用filezilla通过SFTP连接远程服务器的时候,不知道应该选择哪一个密钥。

~ $ ssh-copy-id -h
Usage: /data/data/com.termux/files/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

如果我没有理解错的话你可以用 -i 参数指定密钥

附GPT3.5的答案,可以参考下:
ssh-copy-id 会默认拷贝当前用户的默认 SSH 密钥,一般是 ~/.ssh/id_rsa.pub(如果是 RSA 密钥),或者 ~/.ssh/id_ecdsa.pub、~/.ssh/id_ed25519.pub 等。如果有多个密钥,ssh-copy-id 通常会优先使用默认命名的密钥。

如果你想指定某个密钥文件,可以使用 -i 选项,例如:

ssh-copy-id -i ~/.ssh/your_custom_key.pub user@host

这样可以明确选择要拷贝的密钥。

SSH 客户端通常会按以下顺序查找这些密钥:

  1. ~/.ssh/id_rsa.pub

  2. ~/.ssh/id_ecdsa.pub

  3. ~/.ssh/id_ed25519.pub

看来我是少了一个指定密钥的参数,回头我指定一下看看。

说了很多,但是跟什么都没有说一样。

我touch --help后才发现,原来touch命令可以改文件的访问时间和修改时间,我之前一直用它来创建空白文件用。

按照 ssh 的时候尝试的情况来看,应该是这个顺序,你可以自己验证:

debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type -1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/user/.ssh/id_xmss type -1
debug1: identity file /home/user/.ssh/id_xmss-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1

不是。你这「应该」得毫无根据。

既然你说毫无根据,那我也只能说我也是猜的:

1 个赞