How do I ssh into a box as another user given that host user has no ssh key on the remote machine

Lets say that my user name of my mac machine is John.

I have a fully configured slicehost account. Note that on this slice there is no ssh key for John.

Now I configure this box for ssh acces for user deploy.

On my mac machine I have the private key for user deploy. Slicehost has public key for user deploy.

Again slicehost has nothing for user john.

If I want to ssh into sliceghost box as user deploy do I need to put the public key for John there too?


Solution 1:

Sort of.

You need to put your public key for the account you're coming from on the remote server. If that is your John key, then put that key on the server that you are connecting to using the appropriate account for that server.

In your case, you're connecting as deploy. So, when you connect, you'll type:

ssh deploy@slicehost

If your key for John is in the .ssh/authorized_keys file of the account deploy, then you'll get direct access.

Solution 2:

No. The username has nothing to do with the public/private key pair. It's not recorded anywhere in either key. So long as you place the public key in a user's .ssh/authorized_keys file you can log in as that user by using the private key.

Solution 3:

You will need to specify both that you want to log in as user "deploy" and also specify the identity file for deploy.

ssh -i ~/.ssh/id_deploy.rsa deploy@slicehost

Where id_deploy.rsa is the private key file corresponding to the authorized key you uploaded to the slicehost account.