天天看點

Linux伺服器---ssh登入

Ssh登入

      Ssh是建立在應用層和傳輸層的安全協定,專門為遠端登入回話和其他網絡服務提供安全性。利用ssh可以有效的防止遠端管理中的資訊洩露問題,同時ssh傳輸的資料是經過壓縮的,可以加快傳輸速度。

1、啟動sshd服務。Centos預設已經安裝了ssh,而且該服務預設是啟動的

      [root@localhost wj]# rpm -qa | grep ssh

      libssh2-1.4.2-1.el6.i686

      openssh-askpass-5.3p1-94.el6.i686

      openssh-server-5.3p1-94.el6.i686

      openssh-clients-5.3p1-94.el6.i686

      openssh-5.3p1-94.el6.i686

      [root@localhost wj]# service sshd status

      openssh-daemon (pid  1634) 正在運作...

      [root@localhost wj]# 

2、測試登入

      [root@localhost wj]# ssh [email protected]

      The authenticity of host '192.168.0.119 (192.168.0.119)' can't be established.

      RSA key fingerprint is 36:20:c9:ab:88:1f:47:74:1b:f1:d7:47:55:e0:14:7c.

      Are you sure you want to continue connecting (yes/no)? yes

      Warning: Permanently added '192.168.0.119' (RSA) to the list of known hosts.

      [email protected]'s password: 

      Last login: Fri Aug 10 14:57:45 2018

      already login

      [root@localhost ~]# exit

      logout

      Connection to 192.168.0.119 closed.

3、禁止root登入

      root使用者在Linux系統中擁有最高的權利,如果用root使用者登入就意味着增大了系統的風險。Ssh預設可以使用root登入,為了安全考慮,我們可以禁止root登入。

      1)修改配置檔案“/etc/ssh/sshd_config”,找到“permitRootLogin”将其改為no 

      [root@localhost wj]# gedit /etc/ssh/sshd_config 

      PermitRootLogin no    //這裡預設是yes,而且已經被注釋掉了。取消注釋,改為no

      [root@localhost wj]# service sshd restart           //重新開機服務

      停止 sshd:                                                [确定]

      正在啟動 sshd:                                            [确定]

      2)測試,使用root登入,可以看到沒有權利

      Permission denied, please try again. 

4、設定指定使用者登入

      有時候為了降低系統風險,我們還會設定指定的使用者登入,而其他使用者登入就會拒絕。

      1)修改配置檔案“/etc/ssh/sshd_config”,在最後追加

      AllowUsers david    //允許david登入

      [root@localhost wj]#

      2)測試,分别使用david和weijie兩個使用者登入,其中weijie會登入失敗

      [root@localhost wj]# ssh [email protected]

      [email protected]'s password: 

      Permission denied, please try again.

      [root@localhost wj]# ssh [email protected]

      [email protected]'s password: 

      Last login: Wed Aug 15 17:12:59 2018 from 192.168.0.112

繼續閱讀