Is it safe if my server will create a SSH key pair for my client? Scenario: I(server admin) will create a ssh key pair and put public key into authorized_keys and give the private key to client so he can access my sftp server.
-
Hi @Archemar thank you for responding. but is it safe on the server part? to give out private keys which my server created? – Allan Parcutela Mar 22 '19 at 05:53
-
2Your customer should be generating their own keys and securing them with a passphrase, then giving you their public key to store on the server you manage that they need to access. Their private key should never be given to anyone and it should be encrypted (i.e. secured with a passphrase). – kingmilo Mar 22 '19 at 06:46
-
2Never generate a private key for someone else. Never accept a private key generated for you. – Kusalananda Mar 22 '19 at 07:01
-
@Kusalananda agreed in theory, but the sad reality is that a lot of end users don't necessarily have the know-how to generate an SSH keypair and will complain if you give them the instructions. – Shadur-don't-feed-the-AI Mar 22 '19 at 09:42
-
I think this is will apply to all Unixs, not just UNIX. – ctrl-alt-delor Mar 22 '19 at 09:50
-
If someone create a private key to you, then, it's no private anymore. If someone needs you to access, you just need to provide the public key... – Mar 22 '19 at 16:31
3 Answers
Quick $0.02 because I've got to get ready for work:
Assuming this server isn't protecting actual banks or national security-level secrecy, you're fine.
About the only potential risk I can imagine from this is if a hostile third party intercepted enough of those private keys and the exact time they were generated, they could use that to make predictions about the state and algorhithm of the server's random number generator, which might be useful in some very sophisticated attacks.
... Of course, if they can intercept that many of your private keys you have much bigger problems already.
The safest thing to do would be to let the client generate the keypair and use a trusted channel to send you the public key for inclusion into the authorized_keys
file, but if that isn't an option for whatever reason, your main worry is going to be how to securely get the private key to the recipient and only the intended recipient.

- 31,260
-
+1 for letting the client generate the key pair, but a trusted channel for sending the public key is really not needed. The public key is, as the name says, public. – Johan Myréen Mar 22 '19 at 07:40
-
2The 'trusted' part of the channel is because you want to make sure it's the client's public key you're receiving and not someone's MITM key. – Shadur-don't-feed-the-AI Mar 22 '19 at 07:49
-
Whoever downvoted this, might I ask why? I appreciate constructive criticism. – Shadur-don't-feed-the-AI Mar 22 '19 at 09:25
-
1@Shadur You do need a trusted channel to send public keys: The channel does not have to keep the key secret, but the receiver does have to be able to trust that it came from who it claims to come from. – ctrl-alt-delor Mar 22 '19 at 09:49
-
That's what I said, yes. @JohanMyréen was arguing otherwise. – Shadur-don't-feed-the-AI Mar 22 '19 at 09:50
-
@Shadur Yes, you are right. The public key does not contain sensitive data, but you will of course have to make sure it is the correct one. – Johan Myréen Mar 22 '19 at 09:54
Your customer should be generating their own keys and securing them with a passphrase, then giving you their public key to store on the server you manage and that they need to access. Their private key should never be given to anyone and it should be encrypted (i.e. secured with a passphrase).

- 138
To allow access vith ssh/scp/sftp you can use public/private key pair. (*)
I you generate and install such pair you will controll who will access a specific part of your server (in your case sftp directory).
If you have two or more customer/partner, be sure to generate one key per partner.
This way customer1 will access customer1's part. If set correctly (**), private customer1's key will not access customer2's files, nor any other part of the server.
- (*) assuming as noted by Shadur, that transfert is safe from prying eyes.
- (**) using chroot if possible (this depend on your directory structure).
As noted in my (deleted) comment, this is also a matter of trust from customer's part, but that should be OK, customer already trust you with his file.

- 31,554