User avatar
phaze3131
Posts: 45
Joined: Thu Apr 30, 2015 3:50 am

Can't Change SSH Port

Mon Jan 11, 2016 3:08 pm

Hey guys, I am trying to change my ssh port on my Rpi but I can't seem to get it changed.

I have followed many directions I have found online which say to do this.

sudo nano /etc/ssh/sshd_config

and change "# Port 22" to "Port 12345" or whatever port number I wanted.

Here is what my sshd_config file looks like:

Code: Select all

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   Port 22
#   Protocol 2,1
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no
So I change the Port line and remove the "#"

I restart the service, sudo service ssh restart, also do a reboot.

But still I can only use port 22 to ssh in on my local network.

Thanks for all the help, much much appreciated!

Travis

jahboater
Posts: 4824
Joined: Wed Feb 04, 2015 6:38 pm

Re: Can't Change SSH Port

Mon Jan 11, 2016 5:53 pm

I think you have the client and server config files mixed up.

User avatar
phaze3131
Posts: 45
Joined: Thu Apr 30, 2015 3:50 am

Re: Can't Change SSH Port

Mon Jan 11, 2016 6:10 pm

from this post here:
viewtopic.php?f=36&t=57697

the guy that solved the problem says this:
You need to change /etc/ssh/sshd_config which is the config file for the ssh server, not /etc/ssh_config which is the client config. Then restart ssh.
which is what I did.

jahboater
Posts: 4824
Joined: Wed Feb 04, 2015 6:38 pm

Re: Can't Change SSH Port

Mon Jan 11, 2016 6:15 pm

Here is what my sshd_config file looks like:
# This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.
But that is the client file...

QuietZone
Posts: 89
Joined: Sat Dec 05, 2015 7:13 pm

Re: Can't Change SSH Port

Mon Jan 11, 2016 6:21 pm

It's almost as if someone said: Here's my /etc/passwd file:

Code: Select all

root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:pi
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
(etc)
"If you haven't got anything nice to say about anybody come sit next to me." — Alice Roosevelt Longworth

malicious
Posts: 96
Joined: Thu Jul 24, 2014 10:07 pm
Location: USA

Re: Can't Change SSH Port

Mon Jan 11, 2016 9:14 pm

phaze3131 wrote:from this post here:
viewtopic.php?f=36&t=57697

the guy that solved the problem says this:
You need to change /etc/ssh/sshd_config which is the config file for the ssh server, not /etc/ssh_config which is the client config. Then restart ssh.
which is what I did.
The first post shows changing /etc/ssh/ssh_config - the client file - as indicated by:

Code: Select all

# This is the ssh client system-wide configuration file.  See
...
If that was only an error when making the post, check what port is being used by sshd with:

sudo netstat -tnlp | grep sshd

Otherwise, try again with /etc/ssh/sshd_config and remember to change the 'Port' line in the client configuration file back to 22, or comment it out.

User avatar
phaze3131
Posts: 45
Joined: Thu Apr 30, 2015 3:50 am

Re: Can't Change SSH Port

Mon Jan 11, 2016 10:27 pm

thanks for all the replies.

So we have come to the consensus that the file located here:
/etc/ssh/sshd_config

Is the client file, and the post from before was wrong.

Makes sense, but everywhere I search on google just shows that file for directions on how to change the server port number.

Maybe someone might know the "real" location of the ssh server file so that I can change the port.

Thanks so much for the help

User avatar
rpdom
Posts: 15567
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Can't Change SSH Port

Mon Jan 11, 2016 10:39 pm

phaze3131 wrote:thanks for all the replies.

So we have come to the consensus that the file located here:
/etc/ssh/sshd_config

Is the client file, and the post from before was wrong.
No. That is the correct name of the server file.

But the file you showed and said you changed

Code: Select all

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.
Is not that file. It is /etc/ssh/ssh_config (not sshd_config).

If you have altered the ssh_config file, put it back as it was.
Change the sshd_config file and restart ssh.

The file you want looks like this

Code: Select all

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
...

User avatar
phaze3131
Posts: 45
Joined: Thu Apr 30, 2015 3:50 am

Re: Can't Change SSH Port

Mon Jan 11, 2016 10:57 pm

I'm sorry for wasting everyones time.

I'm stupid and was reading too fast and didn't realize the "d" was there and different from "ssh" and there are 2 different files... reading too fast.

Again, I'm sorry.

User avatar
rpdom
Posts: 15567
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Can't Change SSH Port

Mon Jan 11, 2016 11:12 pm

I suppose it is a bit confusing to just have the one letter difference in the file names. It might have been easier if they had been called ssh_server.conf and ssh_client.conf, but what is done is done.

jahboater
Posts: 4824
Joined: Wed Feb 04, 2015 6:38 pm

Re: Can't Change SSH Port

Tue Jan 12, 2016 7:57 am

Its a linux/unix tradition: 'd' in the name means "daemon" which is the server. So ntpd refers to the Network Time Protocol server etc etc.

If you only use ssh or scp locally then you may well find it easer to edit BOTH files rather than using -p (for ssh) or -P (for scp) every time.

Return to “Troubleshooting”