使用非22端口进行SSH复制

如何将文件从本地复制到某个远程服务器,该服务器在默认端口(22)之外的端口上托管ssh。
我通常使用以下方式连接到服务器:
ssh username@remotehost.com -p 2000
现在我需要使用scp复制文件 user@localbox:~$ scp ~/.ssh/id_rsa.pub user@remotebox.remotedomain.tld:~/.ssh/id_rsa_localbox.pub -p 2000
但是这并不起作用。

sshfs 也是一个选择 :) - user323419
3个回答

scp --helpman scp会告诉你选项是-P port。你还需要在文件参数之前声明这个选项:

scp -P 2000 -i ~/.ssh/id_rsa.pub user@remotebox.remotedomain.tld:~/.ssh/id_rsa_localbox.pub

我也不会相信使用相对路径的链接。如果可以的话,请使用完整路径。
但是,如果你正在复制ID,`ssh-copy-id`也有一个选项可以提供SSH连接选项。
ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 2000 user@remotebox.remotedomain.tld'

有没有一种方法可以在 man 手册中搜索这样的内容? - Nathan Basanese

使用大写字母P。
(在man页中有说明……)

你可以创建文件~/.ssh/config,然后在其中放置远程主机的相关信息。
Host remotehost.com
Port 2000
User username

查看 ssh_config 的手册。
这样你就可以运行 ssh 命令: ssh remotehost.com 以及运行 scp 命令:
scp important_file remotehost.com: