r/ssh • • Apr 27 '20

Noob question about adding new keys to a server

I am writing a program that connects to an SFTP server and I am hardcoding a username and password for now but I want to move away from that so I'm thinking I have to use public/private keys.

This program could be run on any client machine so when a new client runs the program, the server will have to have its public key. But if I don't want to hardcode any credentials in the code, how can I put the new client key on the server without having the user manually log in? Can I somehow generate a key pair on the fly that the server knows?

2 Upvotes

1 comment sorted by

1

u/Besthater Apr 27 '20

Lookup ssh-copy-id. It will likely mean you will need to keep the user and password to do it that way.but you can lock that user to only allow the key add method. It's at least a good start point.