Debian – No such file or directory when trying to create .ssh keys

debiangitlabJenkinsssh-keygen

When I attempt to create ssh keys on my Debian instance :

ssh-keygen -f /home/serverkeys/.ssh/id_rsa 

I am getting the error : Saving key "/home/serverkeys/.ssh/id_rsa" failed: No such file or directory

I am using root user and when I check permissions on the directory :

 ls -ld

I get

drwxr-xr-x 2 root root 4096 Oct 17 08:32 .

I have a number of questions :

1)What am I missing and why is the system not able to automatically create the .ssh directory specified ?

2)Do I need to create another user and switch from using root. I am not sure if the new user will inherit permissions on all packages I have so far since I have installed them with root user profile?

I intend to use the ssh keys for integration between Jenkins and Gitlab as outlined here Jenkins_GitlabIntegration

In the example however the Jenkins instance and Gitlab instance are installed on different servers and yet for my setup they are installed on the same Debian instance and also my Gitlab repo is public.

I am unsure as to whether I still need the ssh key because Jenkins and Gitlab are running on same Debian instance eg would Jenkins still need ssh keys in order to checkout the code from Gitlab.

Best Answer

The -f key_file switch by itself does not create new keys and will also not create a .ssh directory. The -f switch is also used to take an existing key_file as input, when used with other switches. See man ssh-keygen

You need to use the -c option and ssh-keygen-c-f /home/serverkeys/.ssh/id_rsa to create a new private key.