Link to home
Start Free TrialLog in
Avatar of Robogrinch
Robogrinch

asked on

How tro install a public ssh key

Hi, I have a user with a public key and I need to install it on a new linux debian server.

How do I do this.

I need to basically add his key to a user called appserve
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

You need to generate an SSH key for the appserve user, then place it in /home/appserve/.ssh/authorized_keys in the remote server.

Then you should be able to log in like:

ssh appserve@remotehost
Avatar of Robogrinch
Robogrinch

ASKER

HE has generated a key on his linux computer he uses and he has sent me the .pub file..... Now what?
The easy way is for him to do `ssh-copy-id appserve@hostname.example.com` and supply the password (for this one time only), which appends his public key to .ssh/authorized_keys under the appserve users home directory.

Or if you don't want him to ever know the password, copy the public key file to that directory and then
`cat hiskeyfile.pub >> authorized_keys. Check that the .ssh directory and authorized_keys file are readable by the appserve user.  Make sure his public key is recognisable in the authorized_keys file so you can remove it if needed later.
If not already there, create an authorized_keys file in the ../appserver/.ssh folder.
Set access rights using: chmod 600 authorized_keys
Copy the contents of the .pub file to the authorized_keys file and that should be all.
Hi

I have done all of this and all seems fine but when we ssh on to the box it does not ask for a passphrase it wants the users password still!!

Could this have anything to do with the fact the users home directory is /var/www/
Its so annoying, I have done this on many servers before with no issues....

This is what I do and what I get:

chris@ubuntu:~/.ssh$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
chris@ubuntu:~/.ssh$ ssh-copy-id -i ~/.ssh/id_rsa.pub mobileapp@10.10.20.176
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
mobileapp@10.10.20.176's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'mobileapp@10.10.20.176'"
and check to make sure that only the key(s) you wanted were added.

chris@ubuntu:~/.ssh$ ssh 10.10.20.176
chris@10.10.20.176's password: 

chris@ubuntu:~/.ssh$ ^C
chris@ubuntu:~/.ssh$ ssh mobileapp@10.10.20.176
mobileapp@10.10.20.176's password: 

Open in new window

Is /var/www/ a shared home directory for any other users, or is it used for anything else?

From http://www.openssh.com/faq.html#3.14 :
3.14 - I copied my public key to authorized_keys but public-key authentication still doesn't work.

Typically this is caused by the file permissions on $HOME, $HOME/.ssh or $HOME/.ssh/authorized_keys being more permissive than sshd allows by default.

In this case, it can be solved by executing the following on the server.

    $ chmod go-w $HOME $HOME/.ssh
    $ chmod 600 $HOME/.ssh/authorized_keys
    $ chown `whoami` $HOME/.ssh/authorized_keys

Open in new window


Beware, changing ownership or permissions could cause problems for other functions. For now, please login in as `mobileapp` with the password and post the output of:
pwd
ls -ld $HOME $HOME/.ssh $HOME/.ssh/authorized_keys

How about creating a new, personal userid (& home directory) for login, with Group rights to /var/www ?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.