使用非 22 端口的 ssh 复制

Pra*_*tha 20 ssh remote-access scp

如何将文件从本地复制到某个远程服务器,该服务器在默认端口(22)以外的端口上托管 ssh。

我通常使用连接到服务器

ssh 用户名@remotehost.com -p 2000

现在我需要用 scp 复制文件

user@localbox:~$ scp ~/.ssh/id_rsa.pub user@remotebox.remotedomain.tld:~/.ssh/id_rsa_localbox.pub -p 2000

但这不起作用。

Oli*_*Oli 47

scp --help or man scp would have told you the option was -P port. You also need to declare this before the file arguments:

scp -P 2000 -i ~/.ssh/id_rsa.pub user@remotebox.remotedomain.tld:~/.ssh/id_rsa_localbox.pub
Run Code Online (Sandbox Code Playgroud)

I also wouldn't trust ~-relative links. Use full paths if you can.

But if you're copying IDs, ssh-copy-id also has an option to provide SSH connection options:

ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 2000 user@remotebox.remotedomain.tld'
Run Code Online (Sandbox Code Playgroud)