1

For some reason I can no longer scp folders from my desktop Mac to our Linux server.

Here's the error:

(base) my_computer:~ username$ scp -r /source_directory/filename user@server:/home/user/destination
user@server's password: 
scp: realpath /home/user/filename: No such file
scp: upload "/home/user/filename": path canonicalization failed
scp: failed to upload directory /source_directory/filename to /home/user/destination

A few notes on the issue:

  • All of the files do exist. Specifically, /source_directory/filename exists, as does /home/user/destination, but /home/user/filename does not exist, nor should it exist before copying (it will exist after copying from source to destination).
  • I get the same error as above whether I'm trying to copy to the server from my computer's internal drive or from an external drive connected to my computer
  • I do not get this error on any other computers in our network
  • I used to be able to do this without issue
  • I can copy single files (like a .wav) without issue, but not a folder, even if it's empty and even if I'm not using the -r command
  • I have no problem copying from the server to my computer
  • I have no issue with ssh

What could be the cause? What solutions should I try?

Update 1:

When I try this: https://www.reddit.com/r/linuxquestions/comments/uj2y65/strange_scp_r_error/

I only get this:

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

Update 2:

My macOS is Ventura 13.1. None of my other computers uses this version, and I can successfully scp to the server from any of those other computers.

user90664
  • 13
  • 4
  • Does the directory `user@server:/home/user/destination` exist? – ajgringo619 Feb 23 '23 at 23:50
  • @ajgringo619 /source_directory/filename exists, as does /home/user/destination, but /home/user/filename does not exist, not should it before copying. It will exist after copying from source to destination. – user90664 Feb 24 '23 at 00:50
  • Here's a possible solution: https://www.reddit.com/r/linuxquestions/comments/uj2y65/strange_scp_r_error/ – Peregrino69 Feb 24 '23 at 00:54
  • Instead of answering to questions in comments, it's better to [edit](https://unix.stackexchange.com/posts/736671/edit) the question instead. This way it stays up-to-date reflecting your current situation, and everything relevant is readily available. – Peregrino69 Feb 24 '23 at 00:55
  • We've got three different paths listed here: `/source_directory/filename`, `/home/user/destination` and `/home/user/filename` where I think there should be just two. Are any of these actually the same but you've just missed editing them consistently? Do any really have a trailing slash (`/`) that you've missed in the question? – roaima Feb 24 '23 at 11:39
  • 1
    @roaima Yes, the paths in the error are strange, but I have faithfully reported them in the post (with name changes), and all the original paths I used in my command are accurate (i.e., the files really exist, and really exist at the path I entered). – user90664 Feb 24 '23 at 19:56
  • @Peregrino69 Thanks, but that also doesn't work. See my updated post. – user90664 Feb 24 '23 at 20:00
  • I just tested. MacOS Mojave w. OpenSSH 7.9p1 => Debian Bullseye w. OpenSSH 8.4p1. `scp -r /Users/// user@Debian:/home//foo`. No repro, entire was copied into `~/foo/` w/o issues. – Peregrino69 Feb 24 '23 at 20:32
  • @Peregrino69 Thanks for trying. I also can't reproduce this on any other computer. This makes me wonder if the issue is the macOS, which is Ventura 13.1. None of my other computers uses this version. – user90664 Feb 24 '23 at 20:41
  • That actually might be it. With a quick search I found quite a bunch of articles about SSH not working on Ventura. [This one from Yellowduck](https://www.yellowduck.be/posts/ssh-not-working-in-macos-ventura) says *"Ventura comes with OpenSSH_9.0p1 and “This release disables RSA signatures using the SHA-1 hash algorithm by default”.* and has a possible solution to boot :-) – Peregrino69 Feb 24 '23 at 20:48
  • The stated issue there isn't identical to this, but no harm in testing. More possible solutions here: https://superuser.com/questions/1749364/git-ssh-permission-denied-in-macos-13-ventura – Peregrino69 Feb 24 '23 at 20:51

1 Answers1

0

I'm going to guess that you've mangled the paths in your question to avoid leaking what you consider to be sensitive information, but in doing so you've slightly altered the structure of the actual command used.

The path canonicalization failed error is a consequence of scp having been changed to use the SFTP protocol by default, and it now being stricter on paths than before. Specifically the new version requires that directories must not have a trailing slash, and spaces in path names must be escaped with a preceding backslash (\ ).

This will fail:

scp -r /source_directory/filename user@server:/home/user/destination/

This will succeed:

scp -r /source_directory/filename user@server:/home/user/destination

You can temporarily revert to using the original scp protocol with scp -O but this is not recommended, and won't even be an option for much longer. For further detail on the reasons for the change, read answers to the question Is scp unsafe? Should it be replaced with sftp?, particularly those that reference CVE-2019-6111.

roaima
  • 107,089
  • 14
  • 139
  • 261
  • None of those options works. And the paths are not mangled, I was careful to only change the names of things in my post. – user90664 Feb 24 '23 at 19:54
  • Apologies! The -o flag does work. At first I used a lowercase o instead of uppercase O. And now I'm assuming the change that caused this issue was updating the macOS. – user90664 Feb 24 '23 at 21:33
  • @user90664 good to hear you have a temporary fix with `-O` – roaima Feb 24 '23 at 22:03