Linux command
ssh-copy-id 命令
网络
需要网络或远程资源。
常用示例
Copy the default public key
ssh-copy-id [user@host]
Copy a specific public key
ssh-copy-id -i [~/.ssh/id_ed25519.pub] [user@host]
Copy to a host on a non-standard port
ssh-copy-id -p [2222] [user@host]
Dry run
ssh-copy-id -n [user@host]
Force copy
ssh-copy-id -f -i [~/.ssh/id_rsa.pub] [user@host]
说明
ssh-copy-id installs SSH public keys on a remote server's authorized_keys file, enabling passwordless authentication. It connects via SSH (usually with password authentication), creates the ~/.ssh directory and authorized_keys file if needed, and appends your public key. The script ensures correct permissions are set: ~/.ssh directory at 700 and authorized_keys at 600, which SSH requires for security. Incorrect permissions cause authentication failures. By default, ssh-copy-id uses keys from ssh-add -L or the most recent ~/.ssh/id*.pub file. Use -i to specify a different key.
参数
- -i _identity_file_
- Use the specified identity file (public key)
- -p _port_
- Connect to the specified port on the remote host
- -f
- Force mode; don't check if keys already exist on remote
- -n
- Dry run; print keys that would be installed without installing
- -s
- Use sftp instead of cat for copying (useful for restricted shells)
- -o _ssh_option_
- Pass options to the underlying ssh command
FAQ
What is the ssh-copy-id command used for?
ssh-copy-id installs SSH public keys on a remote server's authorized_keys file, enabling passwordless authentication. It connects via SSH (usually with password authentication), creates the ~/.ssh directory and authorized_keys file if needed, and appends your public key. The script ensures correct permissions are set: ~/.ssh directory at 700 and authorized_keys at 600, which SSH requires for security. Incorrect permissions cause authentication failures. By default, ssh-copy-id uses keys from ssh-add -L or the most recent ~/.ssh/id*.pub file. Use -i to specify a different key.
How do I run a basic ssh-copy-id example?
Run `ssh-copy-id [user@host]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i _identity_file_ do in ssh-copy-id?
Use the specified identity file (public key)