8

I'm following this tutorial.

In the section on installing ssh in 16.04 I did:

sudo apt-get install ssh

I tested ssh with:

which ssh

It gave me a path indicating that it's working.

But when I tried:

which sshd

Nothing was produced. No file location no errors nothing?

How can I fix the sshd install?


EDIT:

In answer to steeldriver:

$ echo $path 
/home/hugh/.sdkman/candidates/java/current/bin:/home/hugh/anaconda3/bin:~/anaconda/bin:~/anaconda/bin:~/anaconda/bin:/home/hugh/bin:/home/hugh/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

$ dpkg -L openssh-server
dpkg-query: package 'openssh-server' is not installed  
Use dpkg --info (= dpkg-deb --info) to examine archive files,  
and dpkg --contents (= dpkg-deb --contents) to list their contents.

I should probably mention that I am running all this on a stand alone machine I don't currently have access to a server. Could that explain the problem?

8
  • 1
    Run sudo service ssh restart and see if you can SSH into it Dec 19, 2017 at 18:15
  • 2
    Remember which only searches the current user's path - for a non-privileged user, that might not include /usr/sbin Dec 19, 2017 at 18:18
  • I just tried that and I got the following error "Failed to restart ssh.service: Unit ssh.service not found."
    – Bazman
    Dec 19, 2017 at 18:18
  • @steeldriver so how can I search correctly
    – Bazman
    Dec 19, 2017 at 18:21
  • 1
    More specifically, ssh is a metapackage that should install both openssh-client and openssh-server Dec 19, 2017 at 18:22

3 Answers 3

6

The best way to make this work is to install openssh-client package ( with the client tools) and the openssh-server package (with the server daemon):

sudo apt-get install openssh-client openssh-server

That should solve your problem.

2
  • Installing the ssh package already does this. The problem here is most likely that the SSH server is already running but the OP is just not seeing it with which. Dec 19, 2017 at 22:54
  • Or maybe not, judging from other comments - see my new comment on question. Dec 19, 2017 at 22:58
0

This is a very late response but it may be valid to some folks.

For anyone who may suffer from the same situation as the question says aka which ssh showing up the location but which sshd not showing anything, this simply means that you only have SSH client and no SSH server running in your machine. You can SSH to other computers but those computers cannot ssh back to you.

I tried to install ssh server through:

sudo apt install openssh-server

When I ran which sshd I still could not get anything. What I did was complete removal of SSH through: (mind you if you copy this command it wont ask you for confirmation as I have used -y confirmation)

sudo apt remove ssh --purge -y

I then re-installed ssh (which adds openssh-client and openssh-server) through:

sudo apt install ssh -y

After re-installing ssh that way, for sanity and assurance I restarted SSH daemon through:

sudo service sshd restart

when I did which ssh, I got a response so did when I issued which sshd. I hope this helps someone else. BTW The Ubuntu 18.04 instance was on VirtualBox on a Windows 10 machine, I wanted to access it from Windows (Yes, I know there is WSL and I use it).

0

sudo may give you access to sshd:

$ sudo which sshd
/usr/sbin/sshd

The reasoning goes like:

  • sshd is installed in /usr/sbin
  • Even if your $PATH doesn't include /usr/sbin, sudo generally gives you access to /usr/sbin

By the way, this was alluded by @steeldriver's comment

Remember which only searches the current user's path - for a non-privileged user, that might not include /usr/sbin


Comment on the edit section in your post (only in case other readers got confused by that)

I'm assuming your edit is a reply to:

Please edit your question with the outputs of echo $PATH and dpkg -L openssh-server – steeldriver

But you should have run the command on the server that you installed sshd to, not on your client machine.

I'm not writing this because I'm asking you to fix that (I know this is an old post), but because other readers don't get confused by the output from the wrong place :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .