4

I know for the same user name, we can do:

  1. ssh-keygen
  2. ssh-copy-id

to skip entering the password.

However, in my understanding, this is for remote and client servers both having the same user name.

However, the user name in the remote server didn't exist in my client server. How can I do ssh-copy-id here to skip entering the password?

ex: I need to do as follows:

mark@client:~$ ssh jack@ip_of_remote_server
1
  • 2
    If you've ever used public-key authentication with GitHub, you might have noticed that everyone logs in with the same user ID, git. That user happens to have millions of different public keys associated with it, and the key used determines which GitHub account you get access to.
    – chepner
    Mar 29, 2023 at 19:08

1 Answer 1

8

There's no obligation to have the same user name on the remote machine.

  • Your username on the local machine is jack
  • Your username on the remote machine is john
  • you can append john@<remote IP> to all your commands.

So:

  1. ssh-keygen. This is a local operation, it remains unchanged.
  2. ssh-copy-id john@<remote IP>. This copies the private key of jack@local to the authorized keys of john@remote.
  3. ssh john@remote will log you in.

Note on default values

When you run ssh remote, the program defaults to using the username of your local user. So it's really equivalent to ssh jack@remote

1
  • Additionally you can set the user in the ssh config, eg: echo -e 'Host <remote IP>\n\tUser john' >> .ssh/config
    – ctx
    Mar 29, 2023 at 10:01

You must log in to answer this question.

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