[linux] ssh 포트 변경하기(추가하기)

ssh포트는 기본적으로 22번 포트를 사용한다. 여러가지 이유로 이 포트를 변경해야할 상황이 생긴다.
그때 활용하려고 간단히 써놓는다.
(보통은 알려진 포트를 통한 무차별 공격을 막으려고 포트를 변경하는 경우가 많다.)

1. 우선 현재 상태를 확인한다

root@server:~# netstat -anp | grep LISTEN | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1442/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1442/sshd

22번 포트 사용 확인.

2. 설정을 변경한다.

root@server:~# vi /etc/ssh/sshd_config
# What ports, IPs and protocols we listen for
Port 22
Port 1922             # <== 1922번 포트 추가

3. sshd를 재시작 한다.

root@server:~# service ssh restart
[ ok ] Restarting OpenBSD Secure Shell server: sshd.

4. 확인한다.

root@server:~# netstat -anp | grep LISTEN | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1547/sshd
tcp        0      0 0.0.0.0:1922            0.0.0.0:*               LISTEN      1547/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1547/sshd
tcp6       0      0 :::1922                 :::*                    LISTEN      1547/sshd

22번 외에 1922번이 추가로 오픈된것을 확인할 수 있다.


(220725 추가) 기본적으론 위와 같이 하면 되나.. SELinux의 경우, sshd restart 할때 바인딩 에러가 뜰 수 있다.

Jul 26 10:01:07 localhost sshd[1590]: error: Bind to port 1922 on 0.0.0.0 failed: Permission denied.
Jul 26 10:01:07 localhost sshd[1590]: error: Bind to port 1922 on :: failed: Permission denied.
Jul 26 10:01:07 localhost sshd[1590]: fatal: Cannot bind any address.

이럴 경우 아래의 글을 참고하길..

[linux] ssh 포트 변경하기 (SELinux에서 Bind Permission denied 뜰 때)

Loading

댓글 남기기