Ubuntu – `bash: scp: command not found` while I do have `scp` in `$PATH`

opensshpathscpUbuntu

Here is my screen output:

loug@loug-Satellite-P50-A:~/Downloads$ scp -i ~/--------- browser-uat.zip ubuntu@yabuat:
bash: scp: command not found
lost connection
loug@loug-Satellite-P50-A:~/Downloads$
loug@loug-Satellite-P50-A:~/Downloads$ ssh -i ~/--------- ubuntu@yabuat
ubuntu@ip-172.31.25.135:~$
ubuntu@ip-172.31.25.135:~$ scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
ubuntu@ip-172.31.25.135:~$
ubuntu@ip-172.31.25.135:~$ echo $PATH
/opt/sonar/runner/bin:/snap/bin:/bin:/usr/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8
-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/usr/bin
ubuntu@ip-172.31.25.135:~$
ubuntu@ip-172.31.25.135:~$ echo $SHELL
/bin/bash
ubuntu@ip-172.31.25.135:~$
ubuntu@ip-172.31.25.135:~$ sudo apt install openssh-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssh-client is already the newest version (1:7.2p2-4ubuntu2.1).
o upgraded, 0 newly installed, 0 to remove and 108 not upgraded.
ubuntu@ip-172.31.25.135:~$ exit
logout
Connection to yabuat closed.
loug@loug-Satellite-P50-A:~/Downloads$

See: Annotated screen shot

As shown in the screen copy, the scp command failed with

bash: scp: command not found
lost connection

However after I ssh into the remote server and type scp I can see that command is available, and my $PATH environment is good.

When I tried to install openssh-client, as suggested in many places, I get openssh-client is already the newest version

Now I am stuck and don't know what's wrong with the scp command.

Update

I have openssh-client installed locally, nothing wrong with the local environment:

loug@loug-Satellite-P50-A:~/Downloads$ scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
loug@loug-Satellite-P50-A:~/Downloads$ echo $PATH
/opt/play:/opt/idea/bin:/opt/maven/bin:/home/loug/bin_local:/home/loug/bin:/home/loug/.nvm/versi
ons/node/v7.7.4/bin:/usr/local/share/resin/bin:/home/loug/bin:/usr/local/sbin:/usr/local/bin:/us
r/sbin:/usr/bin:/usr/local/go/bin:/sbin:/bin:/usr/games:/usr/local/games
loug@loug-Satellite-P50-A:~/Downloads$

See: Annotated screen shot

Updates II

A screen copy shows that scp command is available on both ends:

loug@loug-Satellite-P50-A:~/Downloads$ echo 'show we have local scp installed'
show we have local scp installed
loug@loug-Satellite-P50-A:~/Downloads$ scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
loug@loug-Satellite-P50-A:~/Downloads$ echo 'show teh error in scp files to remote'
show the error in scp files to remote
loug@loug-Satellite-P50-A:~/Downloads$ scp -i ~/.keys/yab-ci.pem browser-uat.zip ubuntu@yabuat:
bash: spc: command not found
lost connection
loug@loug-Satellite-P50-A:~/Downloads$ echo 'ssh into remote and test scp on remote'
ssh into remote and test scp on remote
loug@loug-Satellite-P50-A:~/Downloads$ ssh -i ~/.keys/yab-ci.pem ubuntu@yabuat
ubuntu@ip-172.31.25.135:~$ scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
ubuntu@ip-172.31.25.135:~$ exit
logout
Connection to yabuat closed.
loug@loug-Satellite-P50-A:~/Downloads$ echo 'so we proved the scp command available on both end'

so we proved the scp command available on both end
loug@loug-Satellite-P50-A:~/Downloads$

See: Screen shot

Update III

As required by one of the answers, here is the result of the which scp commands on the remote server and local system:

loug@loug-Satellite-P50-A:~/Downloads$ ssh -i ~/.keys/yab-ci.pem ubuntu@yabuat
ubuntu@ip-172.31.25.135:~$ which scp
/usr/bin/scp
ubuntu@ip-172.31.25.135:~$ exit
logout
Connection to yabuat closed.
loug@loug-Satellite-P50-A:~/Downloads$ ssh -T -i ~/.keys/yab-ci.pem ubuntu@yabuat
^Cloug@loug-Satellite-P50-A:~/Downloads$ which scp
/usr/bin/scp
loug@loug-Satellite-P50-A:~/Downloads$

See: Annotated screen shot

Updates IV for Martin

@Martin, here is the result following your instruction

loug@loug-Satellite-P50-A:~/Downloads$ ssh -T -i ~/.keys/yab-ci.pem ubuntu@yabuat
loug@loug-Satellite-P50-A:~/Downloads$ which scp
/usr/bin/scp
scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2

See: Screen shot

Best Answer

It's quite likely that you have your remote PATH set to point to scp only for interactive sessions.

The scp uses non-interactive session.

To verify try to login with ssh -T -i ... and then try to run scp.

You should get the same error.


A different set of startup scripts is (might be) sourced for interactive and non-interactive sessions. And/or different branches in the scripts are taken, based on absence/presence of TERM environment variable (or similar).

You probably need to fix your startup scripts to set the PATH correctly in either situation.

Related Question