Ssh – start sshd with /usr/sbin/sshd in centos

centos6servicessh

I am new in linux but newest in Centos.

using
CentOS release 6.6 (Final)

I can start ssh service via service sshd start and get this output

Generating SSH2 RSA host key:                              [  OK  ]
Generating SSH1 RSA host key:                              [  OK  ]
Generating SSH2 DSA host key:                              [  OK  ]
Starting sshd:                                             [  OK  ]

And can after connect via ssh without problem.

But I need start ssh via /usr/sbin/sshd -D and get this output

Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key

and the service do not start.

Best Answer

The output in your first example is actually from the init script. Check /etc/init.d/sshd if you want to see the full context of what is happening there.

If you're trying to replicate this in a docker container, you will need to replicate. The important commands are:

$KEYGEN -q -t rsa -f $RSA_KEY -C '' -N ''
$KEYGEN -q -t dsa -f $DSA_KEY -C '' -N ''

Which once you expand all the variables, becomes:

/usr/bin/ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -C '' -N ''
/usr/bin/ssh-keygen -q -t dsa -f /etc/ssh/ssh_host_dsa_key -C '' -N ''