Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to setup my home server to use ssh keys but when I follow the tutorial on for setting up ssh keys I get this:

Bad port 'umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys'

I get past the part where you create the key using:

ssh-keygen -t dsa

but the part that asks me to do this:

ssh-copy-id user@servername

is when I get the error above.

Thanks for the help.

share|improve this question
Can you currently ssh into the machine in question using a password? The ssh-copy-id script depends on that capability to work. – teeks99 Jan 22 '11 at 23:24

I'm not sure why that script isn't working for you, but it's just a simple helper script. Try doing it manually (and if there is a problem other than just with the script, it may help you diagnose the issue).

The steps to do it the long way are:

  1. copy your key to the remote server with scp ~/.ssh/ user@servername:~/
  2. ssh to the remote server with ssh user@servername
  3. make sure the .ssh directory exists and has the correct permissions by invoking ssh with something like ssh localhost
  4. put your key in the correct place with cat ~/ >> ~/.ssh/authorized_keys

(you can then delete the file in your home directory on the target machine)

This assumes that you have a dsa key -- if you have an rsa key, use in all cases.

There are some complex ways to do this in a single line, but if you have an issue, they won't be any more useful than the script in helping you figure it out.

share|improve this answer

I got the same error message when I tried to log in with a non-standard port.

To debug, I ran the script, prefixing bash -x. Here's where I ran into issues:

+ ssh -p8882 'umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys'

So it took the command line option '-p8882' and tried to use that as the machine to try to reach. Needless to say it failed. I'd have to see your output to isolate your issue further though.

As teeks99 said, make certain you can log in with your password first though. This should isolate "can't log in with ssh" issues from "ssh-copy-id is broken somehow" issues.

Edited to add:

you can get around some of the issues of not being able to pass any additional arguments to ssh by creating or adding to a file called ~/.ssh/config:

Host shortname
    Port  8882
    IdentityFile ~/.ssh/
    User ubuntu

man 5 ssh_config for details

With roughly this setup, I got the script to work by just issuing ssh-copy-id shortname

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.