5

Is it possible to auto copy my ssh key after a successful first time ssh login with password ?

In other words :

when I type :

ssh user@host

for the first time to that host and I successfully enter the right password I get my ssh key automatically copied to that host without the need to do : copy-ssh-key command manually

2
  • Would be great if there was a way to do this. If you have a large list of servers you don't know which one you will want to copy to until you actually need to log in there. Having to do 2 commands instead of one for each new server is a pain. May 16, 2020 at 2:20
  • Something like ssh me@host 'cat "'$(~/.ssh/id_rsa.pub)'" > ~/.ssh/known_hosts ; exec $SHELL' would work but the problem is you'd get the same line duplicated in the server's known_hosts file every time you log in. May 16, 2020 at 2:26

1 Answer 1

-1

If you want to add your public key to authorized_keys on a remote machine, an answer may be ssh-copy-id (e.g. part of openssh-clients).

2
  • 1
    Thank you for your answer : I know this command. what I want to do is that when I type : ssh user@host and I enter my password I get my ssh key copied automatically.
    – Amine
    Jul 5, 2014 at 21:56
  • I think tonioc is suggesting run this command once for every new host you logon to ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-host.
    – fswings
    Apr 10, 2015 at 18:34

You must log in to answer this question.

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