We connect to all servers that we create in Oracle Cloud environment with ssh public and private key. When creating our database server or normal servers, it will ask us for “ssh public key”. Using private key, it is possible to provide secure and passwordless connection.
You can use the following methods to create an SSH key pair (public and private).
Create SSH Key Pair for Unix, Linux
If you want to connect to cloud servers from a linux or unix machine, you can create a ssh key pair as follows. Our key must be 2048 bit and RSA type.
root@interiva:~# cd $HOME
root@interiva:~# ssh-keygen -b 2048 -t rsa -f mykey
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in mykey.
Your public key has been saved in mykey.pub.
The key fingerprint is:
The key's randomart image is:
| . |
|o .. o S |
| = .o. B |
| .o.+.E . |
| o+o+ o. |
| o=o.+o |
root@interiva:~# ls -l|grep mykey
-rw------- 1 root root 1679 Jan 19 13:45 mykey
-rw-r--r-- 1 root root 395 Jan 19 13:45 mykey.pub
When the command is executed, it will ask for a password. The operation can be done without typing the password. This password will be required to use the private key. If no password is specified, private key can be used without password.
There will be two files with the specified name. In the example above, the file mykey.pub is public key and the file mykey is private key. Public key content will be used on servers in Oracle Cloud environment and private key will be used on machines that will connect to cloud.
Create SSH Key Pair for Windows
You can use PuttyGen (Putty Key Generator) program. PuttyGen will be available after installing the Putty software which can be downloaded from https://www.putty.org/. With PuttyGen you can create ssh key pair as follows.
Select RSA from “Type of key to generate“, type 2048 in the value of “Number of bits in a generated key” and click the Generate button.
By moving the mouse pointer randomly in the empty area, complete the progress bar.
Copy and paste the information in the field “Public key for pasting into OpenSSH authorizek_keys file” into a text editor and save it with a name such as mykey.pub. Be sure to copy the information in the field completely.
After the operation, the public key will be ready. For private key, click Save private key. Confirm it on the screen and save it with the name we use for public key, with a .ppk extension.
At the end of these operations, two files will be created: mykey.pub for public key and mykey.ppk for private key.