这是如何向服务器发出 shh 指令
ssh -p 2222 [email protected]
我想将文件复制logo.png
到public_html
服务器上的文件夹
这是我尝试过的
scp ./logo.png -p 2222 [email protected]:/public_html/
不知道为什么不工作
答案1
每man scp
-P port Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’, because -p is already reserved for preserving the times and modes of the file in rcp(1). -p Preserves modification times, access times, and modes from the original file.
更正后的语法:
scp -P 2222 ./logo.png [email protected]:/public_html/
例子:
$ touch ./logo.png
$ scp -P XXXXX ./logo.png [email protected]:/tmp/
logo.png 100% 0 0.0KB/s 00:00
$
要检查连接性(通过ssh
)并且目标目录存在,请执行以下操作。
$ ssh -p XXXXX [email protected] 'if [ -d /tmp/ ] ; then ls -ld /tmp/ ; fi'
drwxrwxrwt 21 root wheel 31232 Mar 3 23:04 /tmp/
$
答案2
您的命令行没有正确指定端口号。
如手册页所示scp
:
-P port
Specifies the port to connect to on the remote host. Note that
this option is written with a capital ‘P’, because -p is already
reserved for preserving the times and modes of the file.