Why create a new host key files?
You may need a new key file:- Your system is compromised.
- Your keys are stolen.
- You forgotten the passphrase.
- Your application need a new host key.
- You can not read the default system key files stored in /etc/ssh/ directory but your non-root application needs key.
- You got an error message which read as "Could not load host key: /etc/ssh/ssh_host_key*".
ssh-keygen Syntax
The syntax is:ssh-keygen -t 'rsa|dsa|rsa1' -f /path/to/file
Example
Create a host key file in your $HOME/.ssh/myapp as follows. First, create a directory to store your host key file, enter:$ mkdir -p $HOME/.ssh/myapp
To create a host RSAv2 key file, run:
$ ssh-keygen -t rsa -f $HOME/.ssh/myapp/rsa_key_file
Sample outputs:
Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/vivek/.ssh/myapp/rsa_key_file. Your public key has been saved in /home/vivek/.ssh/myapp/rsa_key_file.pub. The key fingerprint is: 73:d0:e9:0a:5d:a3:3f:78:33:5d:0d:fe:e4:f4:25:39 vivek@wks01 The key's randomart image is: +--[ RSA 2048]----+ | | | . . | | . = . | | . = . . + | | . S o E =| | . * . . Bo| | o * . +| | . + | | | +-----------------+Type the following commands to verify the keys:
$ ls -l $HOME/.ssh/myapp/
Sample outputs:
total 8 -rw------- 1 vivek vivek 1675 Oct 29 23:12 rsa_key_file -rw-r--r-- 1 vivek vivek 393 Oct 29 23:12 rsa_key_file.pubYou can now use keys with your app:
$ mycool-app -key $HOME/.ssh/myapp/rsa_key_file -d