[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:security:ssh [2012/09/22 21:49 (UTC)] – [Sources] added a tag mfillpothowtos:security:ssh [2013/11/15 11:36 (UTC)] (current) – [Alternate method of Changing the SSH default port with out changing] ricky_cardo
Line 44: Line 44:
  
 ''Port 4242'' ''Port 4242''
 +
 +
 +===== Alternate method of Changing the SSH default port without changing  =====
 +
 +This suggestion is completely lifted from another site [[http://null.redcodenetwork.ro/changing-the-ssh-port-without-changing-it/]]
 + The idea here is add a call to this script in rc.local so it will run at start up.
 +
 +To use Download sample at the bottom change as you like and save it in /etc/rc.d/  (make it executable to use)
 +Add this sample below to /etc/rc.d/rc.local
 +
 +#add ssh_hide to port 8889
 +  if [ -x /etc/rc.d/rc.ssh_hide ]; then
 +    /etc/rc.d/rc.ssh_hide
 +  fi
 +  
 + What it is doing is making it look like you changed the port ssh is using and provide some additional security.
 +What happens is scanners will continue to see port 22 open and try to go there while your server drops those packets, because the header is not mangled.  Real packets come in on port 8889 and are redirected by iptables to port 22 with mangle in the header so they don't get dropped.
 +
 +<file bash rc.ssh_hide>
 +#!/bin/bash
 +
 +######First, set SSHD back to the default port 22. 
 +######Next, figure out what port or ports you want to do SSH over. 
 +######Were going to use 99, 88, and 8889 here.
 +######Now we take care of the Hypothetical Evil Unprivileged User 
 +######by not accepting anything over those ports in the first place. 
 +######This is only effective for port 8889 but well do all three ports for the sake of completeness.
 +
 +/usr/sbin/iptables -t filter -A INPUT -p tcp -m multiport --dports 99,88,8889 -j REJECT --reject-with tcp-reset
 +
 +######Then, pick a number between 1 and 4294967295 Ill use 0x13F ()
 +######Were going to tell iptables to reject anything without this mark coming into port 22.
 +
 +/usr/sbin/iptables -t filter -A INPUT -p tcp -m tcp --dport 22 -m connmark ! --mark 0x13F -j REJECT --reject-with tcp-reset
 +
 +######Now well tell iptables what ports we will accept for ssh.
 +
 +/usr/sbin/iptables -t filter -A FORWARD -p tcp -m multiport --dports 99,88,8889 -j ACCEPT
 +
 +######In the mangle table we slap our mark on these packets.
 +
 +/usr/sbin/iptables -t mangle -A PREROUTING -p tcp -m multiport --dports 99,88,8889 -j CONNMARK --set-mark 0x13F
 +
 +######Finally in the nat table we tell iptables to send the marked packets back to port 22
 +
 +/usr/sbin/iptables -t nat -A PREROUTING -p tcp -m multiport --dport 99,88,8889 -j REDIRECT --to-ports 22
 +
 +exit 0
 +</file>
 +
 +Note not ipv6 compatible, due to nat (ip6tables not supporting nat)
 +
  
 ===== Forbid root access to your machine ===== ===== Forbid root access to your machine =====
Line 114: Line 166:
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
 <!-- You must also remove the tag-word "template" below. Otherwise your page will not show up in the Table of Contents --> <!-- You must also remove the tag-word "template" below. Otherwise your page will not show up in the Table of Contents -->
-{{tag>howtos security ssh }}+{{tag>howtos security ssh author_Noryungi}}
 howtos:security:ssh ()