Linux SSH – Set Path for scp Command in OpenSSH sshd Daemon

linuxscpssh

I have a curious problem with OpenSSH in SLES 12 SP4 Linux servers.

We install a customized OpenSSH on ourservers, so in each machine we have two versions of OpenSSH, the official package of the operating system and the one that we have compiled.

For the case of SLES 12 SP4 if we run the following command from another server

scp -r directory/. destination_server:/path/to/directory

the following error arises

scp: error: unexpected filename: .

We have verified that the problem is with the scp binary under /usr/bin/scp, which is run by our OpenSSH instead of its scp under its own path.

After searching and testing the solution applied is to remove the execution rights on /usr/bin/scp, so our version of OpenSSH can not use it, and the scp -r from the client works perfectly.

Is there a more elegant to way to tell to the daemon to use the scp binary under its own path instead of /usr/bin/scp?

Best regards

Best Answer

It isn't the SSH daemon which uses the scp program directly, so no, you can't reconfigure it to use another binary. You need to remove all but the "right" scp binaries from the system, or rewrite the PATH environmental variable (preferably in the system default profile), because from the viewpoint of the SSH daemon, scp is just a wrapper for running a remote command.

Basically, here is what scp does:

  1. Initiates the connection through ssh
  2. Sends the scp -t (target path) command through the channel, as if you used the ssh user@target scp -t /this/file command.
  3. Sends the access mode and the file length, ending with '\n'.
  4. Sends the file contents through the SSH channel.

You can emulate scp with the following commands:

ssh user@host scp -t /tmp/aFile.to.create
(enter your password)
C0664 41 originalFileName
The file should contain
these two lines.
(press enter twice)

The third line contains the access rights, the file size, and the original file name. And since the scp command sent "as is", it is up to the target system to find that program for the user.