Linux下修改ssh連接埠和禁止root遠程登入

來源:互聯網
上載者:User

標籤:使用   ar   檔案   sp   art   c   on   log   r   

Linux下修改ssh連接埠和禁止root遠程登入

    我們都知道,ssh預設連接埠號碼是22,要更改連接埠號碼為9688,需要編輯/etc/ssh/ssh_config和/etc/ssh/sshd_config兩個檔案即可;
    禁止root遠程登入,則需要編輯/etc/ssh/sshd_config。(可能部分Linux目錄為/etc/sshd,請根據實際情況修改)

操作步驟如下:

1、編輯/etc/ssh/ssh_config檔案:

[[email protected] ~]# cat /etc/ssh/ssh_config |grep Port
Port 9688

將被注釋掉的Port 22前的注釋符號“#”去掉,並將22改為如上的9688,儲存退出。

2、編輯/etc/ssh/sshd_config檔案:

#vim /etc/ssh/sshd_config

找到PermitRootLogin,將後面的yes改為no,這樣root就不能遠程登入了,儲存退出。

3、重啟ssh:

#/etc/init.d/ssh restart

這樣就成功的更改了ssh連接埠號碼,並禁止掉root遠程登入。值得一提的是,如果您的Linu x中只有root使用者,在關閉root遠程登入之前,請一定要建立一個新使用者,否則會導致無法使用ssh遠程登入伺服器!

本文的內容在Ubuntu下通過測試,其他Linux系統下命令大同小異。

Linux下修改ssh連接埠和禁止root遠程登入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.