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
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 thePATH
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:ssh
scp -t (target path)
command through the channel, as if you used thessh user@target scp -t /this/file
command.You can emulate scp with the following commands:
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.Based on the excellent info in the answer from @Lacek and what the following transcript shows about how
sshd
is managed bysystemd
, I'd say that it ought to be pretty easy to resolve.In the same way that I can add
PATH=/path/to/new/ssh/bin:$PATH
to my bash profile, I can add it to/etc/systemd/system/sshd.service
viaEnvironment="PATH=/path/to/new/ssh/bin:$PATH"
(as documented) or I can add it to/etc/default/ssh
directly.This is how a recent Ubuntu system looks:
We have resolved it :-)
Setting the PATH environment variable was not useful because the PATH is hard coded in the binaries of SSHD (we had verified it watching the environ file under /proc virtual file system for the sshd process).
So the problem was that our directory was added in the configure file in sshd sources after the normal system's path. The solution is to change the line 19346 of the configure file in sources to be
user_path=$t_bindir:$user_path
instead of
user_path=$user_path:$t_bindir
($t_bindir is the path set in --bindir option when executing configure before the compilation with make, $user_path is environment PATH value)
So, to show it clearer, the lines 19343 - 19350 for the configure file in sources remain as
Best regards