为什么安装了`scp`却找不到?

为什么安装了`scp`却找不到?

我运行了下面的命令。

$ scp -i <key> -P <port> <user>@<host>:<path> .
bash: scp: command not found

所以我检查了一下

$ which scp
/usr/bin/scp

然后我尝试

/usr/bin/scp -i <key> -P <port> <user>@<host>:<path> .
bash: scp: command not found

我试过

$ scp
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
           [-i identity_file] [-J destination] [-l limit]
           [-o ssh_option] [-P port] [-S program] source ... target
$ /usr/bin/scp
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
           [-i identity_file] [-J destination] [-l limit]
           [-o ssh_option] [-P port] [-S program] source ... target

据我所知,该计划是

  • 已安装
  • $PATH
  • 跑步

我也已经尝试过了sudo apt-get remove openssh-client openssl然后sudo apt-get install openssh-client openssl

scp以前在我的计算机上运行得很好...发生了什么事以及/或者我该如何解决这个问题?

注意,scp也安装在远程服务器上。

编辑

我按照评论说的,scp举着旗帜跑了。-v

$ /usr/bin/scp -v -i <key> -P <port> <user>@<host>:<path> .
Executing: program /usr/bin/ssh host <host>, user <user>, command scp -v -f <path>
OpenSSH_8.9p1 Ubuntu-3ubuntu0.6, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data <path>
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to <host> [<address>] port <port>.
debug1: Connection established.
debug1: identity file <path> type 0
debug1: identity file <path> type -1
debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Raspbian-10+deb10u4
debug1: compat_banner: match: OpenSSH_7.9p1 Raspbian-10+deb10u4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to <host>:<port> as '<user>'
debug1: load_hostkeys: fopen <path>/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:dBz2B5K8e3bkRhl7S995urLdbvHm34eYlwCUwFyVWNs
debug1: load_hostkeys: fopen <path>/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '[<host>]:<port>' is known and matches the ED25519 host key.
debug1: Found key in <path>/.ssh/known_hosts:54
debug1: ssh_packet_send2_wrapped: resetting send seqnr 3
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: ssh_packet_read_poll2: resetting read seqnr 3
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: <path> RSA SHA256:8c7N6ZX/gpWvY2qQPG4dkTy3LDY51UWaQ2NoaMLhXwE explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: <path> RSA SHA256:8c7N6ZX/gpWvY2qQPG4dkTy3LDY51UWaQ2NoaMLhXwE explicit
debug1: Server accepts key: <path> RSA SHA256:8c7N6ZX/gpWvY2qQPG4dkTy3LDY51UWaQ2NoaMLhXwE explicit
Authenticated to <host> ([<address>]:<port>) using "publickey".
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: client_input_hostkeys: searching <path>/.ssh/known_hosts for [<host>]:<port> / (none)
debug1: client_input_hostkeys: searching <path>/.ssh/known_hosts2 for [<host>]:<port> / (none)
debug1: client_input_hostkeys: hostkeys file <path>/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
debug1: Remote: <path>/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: <path>/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Sending environment.
debug1: channel 0: setting env LANG = "C.UTF-8"
debug1: channel 0: setting env LC_CTYPE = "en_US.UTF-8"
debug1: Sending command: scp -v -f <path>
bash: scp: command not found
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3024, received 2840 bytes, in 0.1 seconds
Bytes per second: sent 28190.5, received 26475.2
debug1: Exit status 127

所以它debug1: Sending command: scp -v -f <path>在失败之前就会说,也许这意味着远程机器出了问题……

编辑2

我尝试通过catssh 来访问我的文件。

$ ssh -i <key> -p <port> <user>@<host> "cat <file>"
bash: cat: command not found

好奇的。

$ ssh -i <key> -p <port> <user>@<host> "pwd"
/home/<user>
$ ssh -i <key> -p <port> <user>@<host> "echo foo"
foo
$ ssh -i <key> -p <port> <user>@<host> "ls"
bash: ls: command not found
$ ssh -i <key> -p <port> <user>@<host> "whoami"
bash: ls: command not found
$ ssh -i <key> -p <port> <user>@<host> "cd"
$

如您所见,一些基本命令无法被识别。

编辑3

echo $PATH在远程机器上运行并得到

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

然而,我ssh -i <key> -p <port> <user>@<host> "echo \$PATH"在本地机器上运行,得到了

${PATH}:/usr/local/ssl/bin

所以我认为这可能是原因。我在远程服务器上有一个文件,/etc/environment内容如下:

PATH="${PATH}:/usr/local/ssl/bin"

这可能是罪魁祸首。

答案1

当我关注时出现了这个问题本指南从源代码构建openssl。我尝试将其添加到我的路径中,但是我做错了。

放入PATH="${PATH}:/usr/local/ssl/bin"不起作用/etc/environment。如果有人能在另一个答案中解释这一点,我会接受那个答案。现在我刚刚删除了文件的内容,现在一切都正常了。

相关内容