1

In my Mac I already have a personal RSA key pair under ~/.ssh
I would like to create a couple of RSA keys in my Mac but for another computer. So I don't want to run some ssh command and replace my existing keys somehow.
Just create some key pairs for users A and B in a custom dir so that I can copy them where I need to and be sure that nothing of my personal SSH settings is replaced/broken.
How can I do this safely?

1

Use the -f flag

eg

% ssh-keygen -f /tmp/foobar
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /tmp/foobar.
Your public key has been saved in /tmp/foobar.pub.
1

Simply use ssh-keygen and when asked for a name for the keypair, use something other than the default path (and optionally filename). You can then find the generated keypair in the location you specify.

  • I would be more comfortable if I avoided the ~/.ssh to be honest. – Jim Aug 24 '17 at 21:48
  • When you run ssh-keygen, literally the first thing it asks is for the file into which to save the key. Including the path. – DopeGhoti Aug 24 '17 at 21:49
  • So ~/.ssh is the default and only used if nothing else is provided? I was concerned that ~/.ssh is somehow modified/updated regardless – Jim Aug 24 '17 at 21:50
  • Only if you use the default for the key file into which to write; if you specifiy another path, your .ssh directory is left untouched. It does not, for example, add the generated public key to ~/.ssh/authorized_keys. – DopeGhoti Aug 24 '17 at 21:51
  • @Jim man ssh-keygen will show you the manual which describes the process (Normally this program generates the key and asks for a file in which to store the private key). – drewbenn Aug 24 '17 at 21:54

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.