8

I need to ssh into a Windows 7 box running MobaSSH as its SSH daemon, and the username on the Windows box contains a space. I can login to the Windows 7 box on an OSX terminal like so:

ssh "Some User"@WindowsHost

So I thought I'd be able to use the scp command on OSX to transfer files between the computers, but I keep getting an error saying "invalid username" whenever I do something like this:

scp myfile "Some User"@WindowsHost:~/myfile

I looked into it and found this question on stackoverflow, but that is mainly about a space within the file paths.

I did find a bug posted about this issue in a specific version of scp, but I'm not sure how to patch scp on OSX. The patch is offered as a .c file.

My last resort is to create a new username on the Windows 7 box and transfer all my profile settings to that new user. It seems like a real hassle given that I can login via ssh, but not scp.

Any tips?

3 Answers 3

10

Add a special configuration to your Mac user's ssh config, usually in ~/.ssh/config

Host mySpaceyUsernameHost
User "Some User"
HostName WindowsHost

You should then be able to scp your file using that named configuration:

scp myfile mySpaceyUsernameHost:~/myfile

I just tried this on OS X 10.7 (Lion) and it worked from one Mac to another, whereas the other options (quoted, or backlash-escaped) did not.... so that's something.

3
  • That worked like a charm. Never heard of the config file, thank you for shedding light on what it can do!
    – ariestav
    Commented Feb 24, 2012 at 5:33
  • Amazingly useful! This also works for OS/X remote hosts. I just did this to scp from OS/X to OS/X, where the remote username had a space in it. Commented Dec 30, 2014 at 20:36
  • For anyone wondering (like me) this also works for Ubuntu =) Escape username spaces in SCP
    – cavpollo
    Commented May 20, 2016 at 0:20
4

Have you tried Some\ User@WindowsHost? The escaped space may work unless there is actually a bug in scp.

Alternatively could you not just change the widows 7 username and remove the space?

2
  • The backslash trick didn't work for me (OS X 10.7) I think it is actually a bug. But a configuration entry for the host did work (see my answer above).
    – bpanulla
    Commented Feb 24, 2012 at 4:20
  • 2
    Yes, I tried that, and it didn't work. Thank you for the suggestion.
    – ariestav
    Commented Feb 24, 2012 at 5:21
0

Replace the spaces with underscores:

scp file "User Name@host":

becomes

scp file User_Name@host:

Working with scp from Linux to Mac OS X.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.