Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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'm trying to generate an RSA key pair for a user on a multi-user remote host so that it can connect to another remote host.

When I run:

ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -C "notes"

It returns: Could not create directory '/var/www/vhosts/domain.com/.ssh.

The "could not create directory" aside, this doesn't seem like the best location to be storing my private key.

Where should I be storing these files? and any ideas as to what I'm doing wrong.

Thanks!

Update I gave the user Sudo rights. and ran keygen via sudo -u user and still got permission denied.

It doesn't seem like I'm logged in properly. When I log in with my users credentials I get -bash-3.2$ instead of user$

share|improve this question

migrated from stackoverflow.com Apr 3 '12 at 18:49

This question came from our site for professional and enthusiast programmers.

    
ssh-keygen puts public and private keys in a user's $HOME/.ssh directory. Are you generating the key as some other user? The account you're using looks to be using a website file directory as its home. – birryree Apr 3 '12 at 17:23
    
@birryree It is. I enabled SSH for an ftp user. I do have root access. Should I be using root and su -u user ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -C "notes" – Bms85smb Apr 3 '12 at 17:32

You should add it as sudoer in a diretory specific to the user of your choice

sudo -u username ssh-keygen -t rsa -b 2048 -f /home/username/.ssh/id_rsa -C "notes"

Cheers

share|improve this answer
2  
sudo -u username ssh-keygen... actually to have the file ownerships right... – Kimvais Apr 3 '12 at 17:27
    
Will this still generate the keys for the correct user or will it generate them as root. Also, is this a bad location to put them? – Bms85smb Apr 3 '12 at 17:27
    
It will generate the keys as root with permissions only for root. So it won't work. You need to use sudo -u username as pointed out by Kimvais. – Matt H Apr 3 '12 at 18:57
    
@MattH Will it then put it in the proper location as well? I don't want it in a web user directory – Bms85smb Apr 3 '12 at 19:37
    
I redited my answer – svassr Apr 4 '12 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .