Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to setup my home server to use ssh keys but when I follow the tutorial on https://help.ubuntu.com/10.04/serverguide/C/openssh-server.html 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
add comment

2 Answers 2

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/id_dsa.pub 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 ~/id_dsa.pub >> ~/.ssh/authorized_keys

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

This assumes that you have a dsa key -- if you have an rsa key, use id_rsa.pub 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
add comment

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
    HostName ec2-0-0-0-0.compute-1.amazonaws.com
    Port  8882
    IdentityFile ~/.ssh/nonstandard.name
    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
add comment

Your Answer

 
discard

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