1

I installed openssh serve on my computer with Ubuntu 16.04. Then I generated rsa key using the following instructions:linux rsa. I also transfered it to host as suggested in the link, though I don't understand why I need to transfer when host is my local computer.

I tried to sudo restart ssh

but got the following error message:

    restart: Unable to connect to Upstart: 
Failed to connect to socket /com/ubuntu/upstart: Connection refused

Do you know what is wrong and how to fix it?

ssh localhost commands works fine.

Also where is private key and can I simply move it to computer that I will be logging from?

  • 1
    You should be using sudo service ssh restart not sudo restart ssh. Also, just out of curiosity, why are you SSHing to your own machine? – nixpower Jan 8 '18 at 0:42
  • @nixpower. Thank you! I am lost, I trying to test connection with key on the same machine before I connect remotely. I am not sure on what machine I should be generating keys and where I should be transferring them and how. – user1700890 Jan 8 '18 at 1:30
  • 1
    You should be generating keys on the machine you want to connect from, and transferring them to the machine you want to SSH to. – nixpower Jan 8 '18 at 2:06
  • 1
    For SSH the private key is intended to never be moved between machines. Only the public. If you set up another machine you generate a new private key and distribute its corresponding public key to all machines that it will need to connect to. For key based login you generate the private key on the client, and transfer the public key to the server. – thomasrutter Jan 8 '18 at 3:56
3

(Adding this as an answer from the comments)

sudo restart ssh

should be:

sudo service ssh restart

The private/public RSA SSH keys are located in ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub, respectively. You can transfer the public key to another machine to connect to it through public key authentication. This can be done via ssh-copy-id like so:

ssh-copy-id username@host

Alternatively, you can append your public key (id_rsa.pub) to the server's /home/username/.ssh/authorized_keys file, which is in essence what ssh-copy-id does.

  • Thank you again. In this line ssh-copy-id username@host how do I specify which key to copy i.e. what if I have generated multiple keys for different machines/servers? – user1700890 Jan 8 '18 at 11:15
  • 1
    @user1700890 You can use the -i flag. ssh-copy-id -i path/to/key username@host. – nixpower Jan 8 '18 at 12:41
  • Also, if the restart doesn't work because an Ubuntu update has somehow uninstalled ssh, you can re-install it with sudo apt-get install openssh-server -y. – sdexp Oct 22 '18 at 8:13
1

If you don't have openssh-server installed and you have made changes in you ssh_config in your system you don't have to restart the service. Just do:

ps aux | grep ssh

If the only process is /usr/bin/ssh-agent then you don't have openssh-server. openssh-server is used when someone wants to connect to your machine (ssh or sftp) and you can find it as sshd process.

Only then you can restart the sshd process with:

sudo service ssh restart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.