Generate ssh certificate with unique filename. Stroring keys in separate files will help make backup without not related keys.
➜ cd /Users/alex/.ssh
➜ ssh-keygen -t rsa -b 4096 -f myproject_test -C "myproject comment"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in myproject_test.
Your public key has been saved in myproject_test.pub.
The key fingerprint is:
SHA256:Bhweh0ETJu7RB/7yKNyAoXiVEHErIL2Je5d8Gvpvii4 [email protected]
The key's randomart image is:
+---[RSA 4096]----+
|o.+oo.X+. |
|...+ X.* |
| .oo* * . |
|o.o* . + |
|o.o.o.. S |
|....=o.= |
| . oo+o . |
|E ..... |
| oo.o+. |
+----[SHA256]-----+
Now copy public key to remote(target) server (111.111.111.111
)
➜ ssh-copy-id -i /Users/alex/.ssh/myproject_test.pub [email protected]
Or if you have custom ssh port
➜ ssh-copy-id -i /Users/alex/.ssh/myproject_test.pub [email protected] -p 7777
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "myproject_test.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh [email protected]"
and check to make sure that only the key(s) you wanted were added.
Try to login
ssh -i /Users/alex/.ssh/myproject_test [email protected]
Or with custom ssh port
ssh -i /Users/alex/.ssh/myproject_test -p 7777 [email protected]
Enter passphrase for key 'myproject_test':
In case when we have multiple servers in one project. We can just copy public key to this servers and use it to have access everywere.
➜ ssh-copy-id -i /Users/alex/.ssh/myproject_test.pub [email protected]
➜ ssh-copy-id -i /Users/alex/.ssh/myproject_test.pub [email protected]
➜ ssh-copy-id -i /Users/alex/.ssh/myproject_test.pub [email protected]
If you set passphrase to certificate probably will want to check it
ssh-keygen -y -f myproject_test
p.s. https://blog.programs74.ru/how-to-copy-ssh-key-using-utility-ssh-copy-id/