20

I am making a new Ubuntu machine as a server, which is supposed to replace an old one with older software.

My question is:

Is it possible to transfer/copy the credentials (in terms of SSH) of the old machine/server to the new machine?

My goal is such that the new machine should supplant the old one and be seen by others as the same machine when using SSH. In other words, I want to ease the upgrading of my network without having to reset SSH-based credentials if one server (and in particular its OS) is replaced.

Thanks

-- Update --

My specific goal was to transfer credentials for the server only, but I do use ssh to replace password based login sometimes, and the suggestions on the client/server connections are also very helpful.

1
  • Please provide more details. Do the users use password or SSH keys? Do you transfer the user accounts and the SSH public keys? – A.L Mar 12 '15 at 10:05
33

The server credentials —that make up the "fingerprint" SSH clients bleat on about if they are incorrect— are actually just keypairs defined in /etc/ssh/sshd_config:

# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

Copy these files over (with their .pub variants), replicate a similar config pointing to them, reload sshd, and things should Just Work™.

You'll also want to copy over client pubkeys (that people have uploaded to their ~/.ssh/authorized_keys but as this is an upgrade, you're probably copying those anyway.

And obviously the fingerprint also relies on the hostname being the same but it sounds like that's what you're doing anyway.

3

You must append the contents of $HOME/.ssh/id_rsa.pub to the other server's $HOME/.ssh/authorized_keys. Luckily, there is a binary for that; ssh-copy-id. Its usage is simple: ssh-copy-id -i .ssh/id_rsa.pub <user>@<remote.server>

1
  • You don't reset SSH-based credentials when you use ssh-copy-id – Tolga Ozses Mar 12 '15 at 10:02

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.