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

快速安裝和配置OpenSSH

日期:2017/2/27 14:17:33   编辑:更多Linux
  下面我介紹在RedHat上快速安裝OpenSSH的經驗。 你可以從 FTP://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-2.3.0p1.tar.gz 下載到openssh,如果從別處下載,必須下載帶有p1後綴的文件。 沒有這個後綴的文件是OpenBSD專用的。 你還需要: Zlib: http://www.freesoftware.com/pub/infozip/zlib/ 其實,你如果沒有的話,那就是你沒有在裝RedHat時選擇它。 現在還來得急,插入RedHat的CDROM,重啟動,把zlib選上,就行了。 OpenSSL 0.9.5a or greater: http://www.openssl.org/ 我是弄的openssl-0.9.5-devel.rpm來安裝的,比較方便, 而且我極力推薦這樣做,因為後面的麻煩比較少。 ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/rpm/openssl-devel-0.9.5a-3.i386.rpm 下面,開始解包: root@local# cd /usr/local/src root@local# tar zxvf openssh-2.3.0p1.tar.gz root@local# rpm -Uvh openssl-devel-0.9.5a-3.i386.rpm 搞定後,開始編譯: root@local# cd openssh-2.3.0p1 root@local# ./configure --prefix=/usr --sysconfdir=/etc/ssh \ --with-tcp-wrappers --with-ipv4-default \ --with-md5-passWords root@local# make root@local# make install root@local# install -m644 contrib/redhat/sshd.pam /etc/pam.d/sshd 如果你已經用RedHat的安裝盤裝上了Zlib庫,又已經把Openssl-devel 的rpm裝好了,這個過程應該不會出錯。(如果有,請告訴我,看我能不能解決) 如果一切順利,那麼: root@local# cd .. root@local# rm -rf openssh-2.3.0p1 下面生成主機密鑰 root@local# ssh-keygen -b 1024 -f /etc/ssh/ssh_host_key -N "" root@local# ssh-keygen -d -f /etc/ssh/ssh_host_dsa_key -N "" 如果這兩步提示“已有文件存在”,那大膽覆蓋好了。 下面的步驟比較重要,看清楚了! 編輯/etc/ssh/ssh_config,添加或改變下面的參數: Host * ForwardAgent no ForwardX11 no RhostsAuthentication no RhostsRSAAuthentication no RSAAuthentication yes PasswordAuthentication yes FallBackToRsh no UseRsh no BatchMode no CheckHostIP yes StrictHostKeyChecking no IdentityFile ~/.ssh/identity Port 22 Cipher blowfish EscapeChar ~ 編輯/etc/ssh/sshd_config,加入或改變下面的參數: Port 22 ListenAddress 210.45.216.120 HostKey /etc/ssh/ssh_host_key ServerKeyBits 1024 LoginGraceTime 600 KeyRegenerationInterval 3600 PermitRootLogin no IgnoreRhosts yes IgnoreUserKnownHosts yes StrictModes yes X11Forwarding no PrintMotd yes SyslogFacility AUTH LogLevel INFO RhostsAuthentication no RhostsRSAAuthentication no RSAAuthentication yes


PasswordAuthentication yes PermitEmptyPasswords no 配置OpenSSH使其使用TCP-Wrappers inetd超級服務器 TCP-WRAPPERS用來啟動和停止sshd1服務。當inetd運行的時候, 它會從配置文件/etc/inetd.conf中讀入配置信息。 (在配置文件中每一行的不同項是用TAB或空格分開) 編輯“inetd.conf”文件(vi /etc/inetd.conf)並加入這一行: ssh stream tcp nowait root /usr/sbin/tcpd sshd –i (“-i”參數說明sshd是被inetd運行的) 怎麼讓這些生效呢? 本來是不用重起的,不過我覺得打命令更麻煩。 那好, root@local# reboot 下面是SSH的用戶配置 root@local# su foo foo@local$ ssh-keygen 運行後會讓你輸入pass phrase,簡單的說就是密碼啦, 不過是加密密鑰的密碼,要記住它,以後可以用ssh-keygen -p改的。 然後會生成 /home/foo/.ssh/identity /home/foo/.ssh/identity.pub 其中沒有pub的是用戶foo的私人密鑰(要保護好), 有pub的是foo的公共密鑰,要被ssh的客戶程序使用。 把公用密匙identity.pub拷貝到遠程機器的“/home/refoo/.ssh”目錄下, 並改名為“authorized_keys”。當然,復制到哪個目錄,取什麼文件名, 取決於用什麼ssh客戶程序,這裡我用openssh,後面我列舉了兩個windows 的ssh客戶程序。 好了,下面你可以在遠程機器上試試了(你得保證遠程機器上裝了openssh的客戶程序。) refoo@remote$ ssh -l foo local.domain.net 成功! 下面我列舉兩個Windows上的SSH客戶軟件 Putty http://www.chiark.greenend.org.uk/~sgtatham/putty.Html TTSSH http://www.zip.com.au/~roca/download.html



取決於用什麼ssh客戶程序,這裡我用openssh,後面我列舉了兩個windows 的ssh客戶程序。 好了,下面你可以在遠程機器上試試了(你得保證遠程機器上裝了openssh的客戶程序。) refoo@remote$ ssh -l foo local.domain.net 成功! 下面我列舉兩個Windows上的SSH客戶軟件 Putty http://www.chiark.greenend.org.uk/~sgtatham/putty.html TTSSH http://www.zip.com.au/~roca/download.html



Copyright © Linux教程網 All Rights Reserved