1. 程式人生 > >linux伺服器修改ssh預設22埠方法

linux伺服器修改ssh預設22埠方法

登入伺服器,開啟sshd_config檔案

vim /etc/ssh/sshd_config

找到#Port 22,預設是註釋掉的,先把前面的#號去掉,再插入一行設定成你想要的埠號,注意不要跟現有埠號重複

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.

Port 22
Port 23456

儲存後退出,執行重啟命令

/etc/init.d/sshd restart 或者 service sshd stop service sshd start

新開一個終端視窗測試23456埠是否可以正常連線伺服器,如果成功則將Port 22刪除,之所以先設定成兩個埠,測試成功後再關閉一個埠,是為了方式在修改conf的過程中,萬一出現掉線、斷網、誤操作等未知情況時候,還能通過另外一個埠連線上去除錯以免發生連線不上必須派人去機房,導致問題更加複雜麻煩。