0

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?

1

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)

  • That's exactly where my error was - I did it for the wrong user. Thank you! – simonalexander2005 Nov 3 '15 at 13:34
1

you need to create the user SSH private/public key is just another method of authentication instead of password authentication.

So you need to create the user that is allowed to use the public private key pair http://www.tecmint.com/add-users-in-linux/

Create the user then you can CHOWN to that user.

  • but the user exists (as I understand it, I didn't set up the server), it just doesn't have a /home directory and you can't log in as it - it's only intended for use in connecting over (S)FTP to another server. – simonalexander2005 Nov 3 '15 at 11:56
  • BUT (S)FTP is SSH so if you can't login as that user it can't exist. i would speak to them – Martin Barker Nov 3 '15 at 11:58
  • I can use sftp weirdUser@host, type the password, and log in fine - but the user doesn't exist as far as I can see (using getent passwd), so I can't give it a private key file – simonalexander2005 Nov 3 '15 at 12:01
  • OK, just found it on the other server... so how do i give it the private key when it only exists on the server I'm connecting to? – simonalexander2005 Nov 3 '15 at 12:02
  • 3
    Ok, to be clear, key pairs should only ever be generated by the person who will be using them, and generated on the system they'll be connecting from. Private jeys are truly private, and should be protected as if they are your password. Public keys on the other hand, do not need to be protected at all. – EEAA Nov 3 '15 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.