[Linux] Setting up SSH?

Hi all,

A friend of mine is running a Linux machine, and I’d like to remotely connect to it via SSH. (I have permission of course. ;))

SSH is installed on the machine, but I don’t know how to configure it to allow me to connect from my computer. Does a special user need to be added? Some config edited to allow remote IPs in?

Hope somone can help me here. :slight_smile:

Mike

You need to supply more details, but generally he needs to have the sshd running, you need to have an account on the machine and hosts.allow should allow your IP…what specific part are you having trouble with?

Sorry for being vague. Bear with me here, I’m quite a newbie. :slight_smile:

Replying to your questions:

  1. How do I start SSH? Would that simply be “sshd start”? Does it run by default on a default Red Hat installation?
  2. I do have an account.
  3. Ah, so I should edit hosts.allow with my IP. Ok. Where is this file located?

Essentially, I’m having trouble from square one. :slight_smile:

A note: I am attemping to SSH from Windows via a terminal emulator (Putty) - which I’ve done before, but I haven’t had to set up the SSH myself before.

Thanks so much,

Mike

Sounds like you should already be able to log in. I presume he has some registered domain name, or you at least know his ip?

Don’t know what Redhat’s doing by default nowadays. If you wanna find out if it’s running, run something like “ps aux | grep sshd”.

Can anyone else ssh in? Does he have a router that’s blocking access? What happens when you try to connect right now? Any other info you have that might be applicable?

if sshd isn’t running already, the command to start it is :
service sshd start

Once it’s running properly, he needs to verify that the machine can ssh to itself. Once that’s done, you need the ip, of course.

PuTTY is a great prog, by the way. My favorite windows ssh client.

Thank you for the responses.

I have the IP - however the computer is hooked up to a router. (with several other computers) I suppose this could be a problem.

Upon my connection attempts at the moment, I just get a connection refusal. No terminal login or anything. (however, I don’t know if SSHD is even running.) I’m just trying to figure out all the steps to get to the point of a successful connection.

Am I correct to think that I must add my IP to hosts.allow also?

Thank you,

Mike

Some Linux distributions have the firewall enabled by default. If that’s the case, try turning it off and see if it works. If it does work, I recommend you turn it back on and configure it to allow SSH access.

Alright, first we need to find out if the computer is listening on the ssh port (22), for that we’ll use “netstat -a” at a command prompt, should get something like this:

You’ll see a list like this of all ports the machine is listening too, if sshd is running you’ll a line like the bolded one above.

If it’s not running you’ll need to start it. If sshd was installed as part of the redhat install there will be a control script for it in /etc/init.d (or /etc/rc.d/init.d for older RH installs) So ‘cd’ to this directory and run the sshd script to see it’s status:

If it’s not running it’ll say something about the process being stopped. In that case you’ll run the script again, as root:

If sshd has never been stated on the machine before it will go through a little song and dance to creat it’s key’s and whatnot, just follow the prompts and you’ll be fine.

Now if sshd is running but you’re still getting connection refused messages then a couple of things could be wrong. First off try sshing from the linux box to itself:

ssh localhost

It should let connect just fine, even if tcp_wrappers or a firewall is blocking other access. If you still get connection refused messages like this double check that sshd is in fact running.

If you’re able to connect locally like this but ar still unable to connect from your winders box then it may be a hosts.allow or firewall problem. For hosts.allow add the following line:

sshd:ALL

Then restart sshd so it reads in the new hosts.allow info:
/etc/init.d/sshd restart

you can worry about tightening up the security later, right now we’re just concerned with getting it working. Try again from the winders box. If it still isn’t working then check the sshd config file, should be:
/etc/ssh/sshd_config

or something similar, if in doubt just type “locate sshd_config”

Read over the file and look for anything that would indicate whether or not sshd is configured to accecpt connections from certain IPs or not. You probably won’t find anything but it’s worth checking.

If you’ve done all of the above and still can’t connect then it may be a default Redhat firewall in which case I can’t help you much since I’ve never let RH install a firewall for me, as all of my machines are behind a dedicated firewall machine which I configure by hand. Check /etc/init.d and see if there is a firewall script in there, if so something like:
./firewall stop

should turn it off. Hope this helps.

If you need more help after this post again or email me direct and we’ll see what else we can try!

Doh! I just read your other post about being behind a router. You’ll need to configure the router to forward port 22, the ssh port, to whatever IP the linux box is running on. Then from your machine you’ll ssh to the address of the router and it’ll happily send all that traffic to the linux box and life should be good.

Cheers,