LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   ssh to non-22 not working, edited sshd_config and restarted sshd (https://www.linuxquestions.org/questions/linux-server-73/ssh-to-non-22-not-working-edited-sshd_config-and-restarted-sshd-897540/)

NirvanaBaby 08-16-2011 01:24 AM

ssh to non-22 not working, edited sshd_config and restarted sshd
 
So according to at least three sites I've been to, all I should need to do is edit the one line in sshd_config to another port (29 in this case, which is unused) and restart sshd. I've set my router to port forward to 29 on my server. 22 works. 29 works when I ssh locally but not from another computer on the internal network or from outside. using Fedora 12. Help?? Tanx in advance.

kirukan 08-16-2011 02:10 AM

what is the output? for
Quote:

netstat -pnl | grep sshd

NirvanaBaby 08-16-2011 02:15 AM

Kirukan, grep output is:

tcp 0 0 0.0.0.0:9222 0.0.0.0:* LISTEN 1808/sshd
tcp 0 0 :::9222 :::* LISTEN 1808/sshd

What is the 1808 business? No clue here, never muddled in this before. Thanks for your help.

kirukan 08-16-2011 02:20 AM

The whole clue are there, instead of asking all you just refer either from manpage or web.
1808 is process id
9222 is port listening sshd.

Be patient with forum members Dear Friend..

druuna 08-16-2011 02:20 AM

Hi,

Quote:

tcp 0 0 0.0.0.0:9222 0.0.0.0:* LISTEN 1808/sshd
tcp 0 0 :::9222 :::* LISTEN 1808/sshd
The green part is the port that sshd listens on and the blue part is the PID of the sshd process (do a ps -ef | grep 1808)

In your first post you mention sshd listens on port 29, it seems that is not the case. It listens on 9222.

Hope this helps.

NirvanaBaby 08-16-2011 02:29 AM

Thanx, I did now change port from 9222 to 29 in config file, missed that. restarted sshd, failed to stop. going back to 9222. restarts ok but no ssh. Thanks for the quick replies, all...

druuna 08-16-2011 02:42 AM

Hi,
Quote:

Originally Posted by NirvanaBaby (Post 4444240)
Thanx, I did now change port from 9222 to 29 in config file, missed that. restarted sshd, failed to stop. going back to 9222. restarts ok but no ssh. Thanks for the quick replies, all...

Am I assuming correctly that this is not fixed?

If so (as root user):

- Stop the sshd daemon,
- Change the port/listenaddress,
- Start sshd daemon.

Can you post the output of the following command (as root user): egrep -i "listen|port" /etc/ssh/sshd_config

Hope this helps.

NirvanaBaby 08-16-2011 11:02 PM

Druuna, you assume correctly, not fixed. I did what you said. Stopped daemon, changed port, started daemon. Here's what my file looks like:
#Port 22
Port 9222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

I also want to ask you about your use of egrep as, though I'm not a noob, I'm not a fecking expert and had to google egrep. Was your use of a pipe in "listen|port" a logical OR? it seems to be because anything with either "listen" or "port" was returned. Any education on the use of egrep would be bonus. here is my output from egrep, though it's the same as my paste above:
[root@Dysnomia ssh]# egrep -i "listen|port" /etc/ssh/sshd_config
#Port 22
Port 9222
#ListenAddress 0.0.0.0
#ListenAddress ::


Tanx!

druuna 08-17-2011 02:34 AM

Hi,
Quote:

Originally Posted by NirvanaBaby (Post 4445153)
Druuna, you assume correctly, not fixed. I did what you said. Stopped daemon, changed port, started daemon. Here's what my file looks like:
#Port 22
Port 9222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

It isn't clear to me if you want to use port 29 as mentioned in your first post or port 9222 as shown in the above output. But either should work, even if the content of the sshd_config file is very minimalistic.

You mention that this is not fixed, what exactly do you mean by that? Assuming you want to use port 29 and changed the sshd_config file accordingly; Are you able to use ssh locally (I.e: ssh -p 29 localhost and ssh -p a.b.c.d and/or are you able to access this box from another box?

If you can ssh locally it proves that the sshd daemon is listening and working. You can make sure by checking with this command: netstat -pln | grep ssh.
If you cannot access this box from a remote box you might have a firewall in place that needs to be changed (it probably allows access to/from port 22, but not any other port).

Quote:

I also want to ask you about your use of egrep as, though I'm not a noob, I'm not a fecking expert and had to google egrep. Was your use of a pipe in "listen|port" a logical OR? it seems to be because anything with either "listen" or "port" was returned.
The part between the double quotes is a regular expression and thus the | is seen as an OR. Grep normally only takes 1 pattern, using egrep (or grep -E) tells grep that an extended regular expression is being used. Have a look at man grep, especially the REGULAR EXPRESSIONS section.

Hope this helps.

lithos 08-17-2011 05:15 AM

if your IPTABLES are up and running then you need to make it allow to connect to port 9222

NirvanaBaby 08-17-2011 01:02 PM

Thanks all!
 
Thanks to everyone who gave assistance on this. It was COMPLETELY UNECESSARY however. I'm surprised no one asked "why are you doing this?" All i wanted to do is ssh to more than one box from the outside when all I need to do to accomplish this is remote into one and from there, remote to the other. No need for more than one port on firewall. >< Hey, at least I learned egrep, thanx!

Reuti 08-18-2011 01:46 AM

Just to note, that you could also create a tunnel between the final machine and the local one, in case you want to copy something between these two without copying it first to the machine in the middle. The -L option to ssh will do it.

NirvanaBaby 08-18-2011 09:32 AM

Thanks for tunnel suggestion
 
I didn't know that, Reuti, I'll research -L.

Reuti 08-18-2011 09:48 AM

First you need to create the tunnel by logging in to the machine in the middle:
Code:

$ ssh -N -L 1234:final_machine:22 middle_machine
If you don’t get any further complains, then the tunnel was created. Then use another session to issue:
Code:

$ ssh -p 1234 localhost
and you will be connected to the final machine. Just note that for scp the option for the port is in uppercase.


All times are GMT -5. The time now is 04:11 PM.