歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> OPENSSH的安裝和配置

OPENSSH的安裝和配置

日期:2017/2/27 9:46:51   编辑:更多Linux
  OPENSSH的安裝和配置 一、 概述 傳統的遠程網絡訪問服務在本質上都是不安全的,因為它們在網絡上用明文傳送口令和數據,很容易被截獲,其安全驗證方式也容受到中間人的攻擊。通過使用OPENSSH,你可以把所有傳輸的數據進行加密。 SSH是由客戶端和服務端的軟件組成的,有兩個不兼容的版本分別是:1.x和2.x。它需要不同的客戶端。OPENSSH同時支持SSH1和SSH2。 二、 OPENSSH的安全驗證方式 OPENSSH提供兩種級別的驗證方式: 1、 基於口令的安全驗證:只要你知道服務器上的帳號和口令,那麼你可以登錄到遠程主機上。口令和數據在傳輸過程中都會被加密。 2、 基於密鑰的安全驗證:采用此方式驗證你必須在遠程服務器上為自己創建一對密鑰(不對稱密鑰對),把公有密鑰放在遠程服務器上自己的宿主目錄中。而私有密鑰則由自己保存。 三、 所需軟件 openssl-0.9.5a.tar.gz 下載網址:http://www.openssl.org openssh-2.5.2p2.tar.gz 下載網址:http://www.openssh.org 四、 安裝步驟 下面的安裝選項根據你自己的情況可適當調整,如果有不明白的地方可以參考README、INSTALL文檔。此文環境假定所有源文件都在/var/tmp下: 4. 1安裝OPENSSL [root@mail tmp]tar xzpf openssl-0.9.5a.tar.gz [root@mail tmp]cd openssl-0.9.5a [root@mail openssl-0.9.5a]./config –t [root@mail openssl-0.9.5a]./config --prefix=/usr --openssldir=/etc/ssl 編輯Makefile.ssl文件更改MANDIR=$OPENSSL/man為MANDIR=/usr/man。 [root@mail openssl-0.9.5a]make [root@mail openssl-0.9.5a]make test [root@mail openssl-0.9.5a]make install [root@mail openssl-0.9.5a]cd .. [root@mail tmp]rm –rf openssl* 4.2 安裝OPENSSH 在安裝OPENSSL之前確認你的系統中已安裝了zlib庫,可用下面的命令來檢查一下,若沒有不要的猶豫,它就在你的系統安裝光盤中,馬上安裝吧! [root@mail tmp]rpm –qi zlib [root@mail tmp]tar xzpf openssh-2.5.2p2.tar.gz [root@mail openssh-2.5.2p2]./configure \ >--prefix=/usr \ >--sysconfdir=/etc/ssh \ >--with-tcp-wrappers \ >--with-ipv4-default \ >--with-ssl-dir=/usr/include/openssl [root@mail openssh-2.5.2p2]make [root@mail openssh-2.5.2p2]make install [root@mail openssh-2.5.2p2]install –m 644 contrib/redhat/sshd.pam \ /etc/pam.d/sshd [root@mail openssh-2.5.2p2]cd .. [root@mail tmp]rm –rf openssh* 五、 配置OPENSSH 5.1 在inetd服務器中起動SSHD守護程序只需加入下面一行(建議在起動TELNET守護程序這一行更改,以完全代替TELNET): ssh stream tcp nowait root /usr/sbin/tcpd sshd –I 5.2 SSH客戶端配置文件/etc/ssh/ssh_config,一般情況下我們在多使用WINDOWS平台的客戶端,此配置文件只有客戶端不指定任何參數的情況下才使用,其內容如下: # $OpenBSD: ssh_config,v 1.9 2001/03/10 12:53:51 deraadt EXP $ Host * ForwardAgent no ForwardX11 no RhostsAuthentication no RhostsRSAAuthentication yes RSAAuthentication yes PassWordAuthentication no


FallBackToRsh no UseRsh no BatchMode no CheckHostIP yes StrictHostKeyChecking yes IdentityFile ~/.ssh/identity IdentityFile ~/.ssh/id_dsa IdentityFile ~/.ssh/id_rsa1 IdentityFile ~/.ssh/id_rsa2 Port 22 Protocol 2,1 Cipher blowfish EscapeChar ~ 5.3 SSH服務器端配置文件/etc/ssh/sshd_config,關於下面各個參數的含義請參考使用手冊,此例中使用第二種認證方式(基於密鑰的認證)以提高安全性。 # $OpenBSD: sshd_config,v 1.34 2001/02/24 10:37:26 deraadt Exp $ Port 22 #Protocol 2,1 #ListenAddress 0.0.0.0 #ListenAddress :: HostKey /etc/ssh/ssh_host_key HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key ServerKeyBits 768 LoginGraceTime 600 KeyRegenerationInterval 3600 PermitRootLogin without-password # # Don't read ~/.rhosts and ~/.shosts files IgnoreRhosts yes # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication #IgnoreUserKnownHosts yes StrictModes yes X11Forwarding no X11DisplayOffset 10 PrintMotd yes KeepAlive yes # Logging SyslogFacility AUTH LogLevel INFO #obsoletes QuietMode and FascistLogging RhostsAuthentication no # # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts RhostsRSAAuthentication no # RSAAuthentication yes # To disable tunneled clear text passwords, change to no here! PasswordAuthentication no PermitEmptyPasswords no # Comment to enable s/key passwords or PAM interactive authentication # NB. Neither of these are compiled in by default. Please read the # notes in the sshd(8) manpage before enabling this on a PAM system. ChallengeResponseAuthentication no # To change Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #AFSTokenPassing no #KerberosTicketCleanup no # Kerberos TGT Passing does only work with the AFS kaserver #KerberosTgtPassing yes #CheckMail yes #UseLogin no #MaxStartups 10:30:60 #Banner /etc/issue.net #ReverseMappingCheck yes #Subsystem sFTP /usr/libexec/sftp-server 六、 生成認證密鑰 當采用密鑰認證方式時,第個用戶在遠程服務器上必須生成自己的密鑰;下面我們就以實例的方式敘述此過程: 6.1 為服務器上的用戶robin生成rsa1認證密鑰: [root@mail tmp]su robin [root@mail tmp]ssh-keygen

此命令運行時將會提示你密鑰的存放位置,直接回車;在提示你輸入passphrase時建議你輸入一個不短於10個字符的英文句子,以防止你的私有密鑰被別人盜用。它會在當前用戶的個人目錄個生成兩個文件: ~/.ssh/identify robin的私有密鑰 ~./ssh/identify.pub robin的公用密鑰 6.2 不要忘記idnentify.pub更名: [root@mail .ssh]mv identify.pub authorized_keys 6.3 拷貝文件到安全的地方,在服務器上你的宿主文件夾中刪除identify文件。 七、 使用PuTTY客戶端登錄 終於到檢驗我們工作結果的時候了,在WINDOWS平台的SSH客戶端我推薦使用Putty,很好用,不像其它一些客戶端只支持基於口令的安全驗證;你可以在這裡下載: http://www.chiark.greenend.org.uk/~sgtatham/putty.Html. 在連接服務器時不要忘記在connect->SSH中指定你的私有密鑰的存放位置,輸入創建密鑰時的passphrase,如果不出意外你就可以安全地行程控制你的服務器了。



~/.ssh/identify robin的私有密鑰 ~./ssh/identify.pub robin的公用密鑰 6.2 不要忘記idnentify.pub更名: [root@mail .ssh]mv identify.pub authorized_keys 6.3 拷貝文件到安全的地方,在服務器上你的宿主文件夾中刪除identify文件。 七、 使用PuTTY客戶端登錄 終於到檢驗我們工作結果的時候了,在WINDOWS平台的SSH客戶端我推薦使用Putty,很好用,不像其它一些客戶端只支持基於口令的安全驗證;你可以在這裡下載: http://www.chiark.greenend.org.uk/~sgtatham/putty.html. 在連接服務器時不要忘記在connect->SSH中指定你的私有密鑰的存放位置,輸入創建密鑰時的passphrase,如果不出意外你就可以安全地行程控制你的服務器了。



Copyright © Linux教程網 All Rights Reserved