Ssh – Give private key ownership to user without /home

chownprivate-keysftpssh

so I am looking to set up ssh private/public keys between two servers, for use with sftp (and ultimately lftp using sftp – but one step at a time).

I have created the private and public keys, and found that in order to use them, the private key must be owned and only readable by the user connecting.

The problem is, the user I am connecting as doesn't have a /home/ directory on either server (and only exists on the remote server), so when I try to chown, I get chown: invalid user: {userName} – because it doesn't exist locally.

Can anyone suggest a way around this?

–Edit–

I used getent passwd on both servers, and found that the user only exists on the server I'm sftping to. So when I connect as that user (sftp weirdUser@remoteHost), how can I do this using private/public keys?

Best Answer

You need a ~/.ssh/config file on your local server that will associate your key with the user on the remote server such as:

Host yourremoteserver
    User weirduser
    IdentityFile /home/mylocaluser/.ssh/id_rsa

If you want to create a unique key just for weirduser@yourremoteserver use the -f option on ssh-keygen:

ssh-keygen -t rsa -b 1024 -f weirduser

and replace the IdentifyFile line in the ~/.ssh/config file with:

IdentityFile /home/mylocaluser/.ssh/weirduser

Whichever key you decide to use (the default id_rsa or weirduser), you'll need the contents of the corresponding .pub file inserted into weirduser's authorized_keys on the remote server. After you have your config file setup, try (it'll prompt for the remote password then copy the .pub file to the correct authorized_keys):

ssh-copy-id weirduser@yourremoteserver

(Or you could do this manually)