centos SSH配置詳解

來源:互聯網
上載者:User

標籤:

基本概念 
 linux內建的ssh為OpenSSH

ssh協議提供兩種使用者認證方式 
  1、 基於口令的安全認證:使用使用者名稱、密碼的方式對登入使用者進行認證 

  2、 基於密鑰的安全認證:使用公開金鑰和私密金鑰對的方式對登入使用者進行認證

OpenSSH的rpm包由四部分組成(預設已安裝) 
  openssh-4.3p2-26.el5.i386.rpm(一定要先安裝這個rpm包) 

  openssh-server-4.3p2-26.el5.i386.rpm 

  openssh-clients-4.3p2-26.el5.i386.rpm 
  openssh-askpass-4.3p2-26.el5.i386.rpm (在圖形介面下使用ssh服務時才需要)

openssh的主設定檔為: 
  /etc/ssh/sshd_config  #ssh伺服器的設定檔 

  /etc/ssh/ssh_config  #ssh用戶端的設定檔 

openssh支援使用scp(加密的拷貝)和sftp(加密的ftp)等用戶端程式進行遠程主機
的檔案複製 

 

OpenSSH伺服器端配置執行個體1:基於使用者名稱密碼的登入方式 
1、vi /etc/ssh/sshd_config (以下列出的是常用配置) 

#Port 22  #定義ssh監聽的連接埠號碼,預設為22 
#Protocol 2,1 #設定使用ssh協議的順序,先使用ssh2,如果不成功再使用ssh 

Protocol 2  #設定只使用ssh2協議 
#ListenAddress 0.0.0.0  #設定ssh伺服器綁定的ip地址,預設為所有可用的ip地址 

#PermitRootLogin yes #設定是否允許root登入,預設允許 
#PermitEmptyPasswords no #設定是否允許空密碼的客戶登入,預設為禁止 
PasswordAuthentication yes #設定是否使用口令認證方式,如果要使用公開金鑰認證方式,可將其設定為no 

2、重啟ssh服務 

   /etc/init.d/sshd restart 
3、如果啟用了iptables,則需要添加如下語句來開放ssh 

   iptables –I INPUT –p tcp –dport 22 –j ACCEPT

     iptables –I OUTPUT –p tcp –sport 22 –j ACCEPT   
3、windows用戶端登入  

  使用xshell、putty、securecrt等用戶端軟體都可以登入 

4、linux用戶端登入  

  1、安裝openssh-clients (預設已安裝)  

  2、ssh命令的基本使用  

    ssh [email protected]  

      ssh –l username sshserver 



OpenSSH伺服器端配置執行個體2:基於公開金鑰認證的ssh登入 
1、 擷取puttygen程式 
可以使用puttygen程式來產生金鑰組,為
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html  
2、 產生密鑰 
 
      

 

3、 儲存密鑰 


4、 傳輸公開金鑰檔案到ssh伺服器 
  公開金鑰檔案是可以公開給所有使用者的,無需考慮安全問題,可以使用ftp、u盤都可以 

5、 轉換公開金鑰檔案格式 
  由於puttygen產生的公開金鑰檔案格式與openssh的格式不相容,因此還要在linux中使用openssh內建的ssh-keygen對其進行轉換,openssh存放公開金鑰的目錄預設為/root/.ssh,如果沒有這個目錄,可以手工建立 

  [[email protected] ~]# mkdir .ssh 
  [[email protected] ~]# ssh-keygen -i -f wtcentoskey.pub > /root/.ssh/authorized_keys  
如果有多個公開金鑰需要添加,可使用下面的命令將公開金鑰檔案追加到authorized_keys中 

[[email protected] ~]# ssh-keygen -i -f abcxyz.pub >> /root/.ssh/authorized_keys 

6、 在ssh伺服器上啟用公開金鑰認證 
[[email protected] ~]# vi /etc/ssh/sshd_config 
 
7、 重啟sshd服務 
  [[email protected] ~]# /etc/init.d/sshd restart 

8、 用戶端用putty來登入ssh伺服器 
 

 

Putty成功的串連到ssh伺服器後會出現如下的介面 
 
 
附:如果使用xshell則更加簡單,因為xshell產生的金鑰組和openssh是完全相容的,無需轉換,只需要將公開金鑰檔案追加到/root/.ssh/authorized_keys中即可,如下: cat /root/wtxshell.pub >> /root/.ssh/authorized_keys

centos SSH配置詳解

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.