ºìÁªLinuxÃÅ»§
Linux°ïÖú

ʹÓÃOpenSSH ½¨Á¢¸üÓÐЧµÄ°²È«ÐÔÄÜ

·¢²¼Ê±¼ä:2006-09-11 08:50:24À´Ô´:ºìÁª×÷Õß:qingniaox
¡¡¡¡ÀÏLinux¹ÜÀíÔ±ÃǶ¼ÖªµÀSSH£¨°²È«shellЭÒ飩£¬ÕâÊÇËûÃÇÈí¼þ¹¤¾ßÏäÖÐ×î±ãÀû×îÓÐÓõŤ¾ß¡£ÔÚ¹¤×÷Õ¾X Windows»·¾³ÏÂʹÓöà¶Ë¾ºÕù»òÕßͨ¹ýScreen utility£¬Linux·þÎñÆ÷¹ÜÀíÔ±»òÕßÆäËü»ùÓÚUnix²Ù×÷ϵͳµÄ·þÎñÆ÷¹ÜÀíÔ±£¬ÄÜÇáËɵØͬʱ¹ÜÀí¼¸¸öϵͳ¡£ÍøÂç¹ÜÀíshell»òÕßPerl½Å±¾£¬ÄÜÀûÓÃSSHÔÚ¶à¸ö·þÎñÆ÷Éϼòµ¥°²È«µØ×Ô¶¯Ö´Ðй¤×÷¡£

¡¡¡¡ÍøÂçshellЧӦRSH±ÈSShÒª³¤¡£µ«ÊÇSSHÔÚÆ书ÄÜÖÐÌí¼ÓÁËÇ¿´óµÄ¼ÓÃܹ¦ÄܺÍÊý¾ÝѹËõ¹¦ÄÜ£¬²¢ÇÒ´ó¶àÊýÏÖ´úSSHʵÏÖÔÚͬһ°üÄÚÌṩSFTPºÍSCP£¬ËüÃÇÓÃÓÚÍøÂçÖеݲȫÎļþ´«Êä¡£

¡¡¡¡×îÁ÷ÐÐ×îÆÕ±éµÄSSHʵÏÖÒÔOpenSSHµÄÐÎʽ³öÏÖ£¬ËüÊÇÓÉOpenBSDÉçÍŹ¹Ë¼ºÍά»¤µÄÏîÄ¿¡£OpenSSH±»µ¼Èëÿһ¸ö²Ù×÷ϵͳƽ̨£¬°üÀ¨Î¢ÈíµÄWindows£¬ËäÈ»ÔÚWindow»·¾³ÖÐËü×î¹ã·ºµÄÓ¦ÓÃÊÇ£º×öΪ»ùÓÚUnixϵͳÉϵÄOpenSSH·þÎñÆ÷µÄ¿Í»§¶Ë¡£ÕâЩ»ùÓÚUnixϵͳ°üÀ¨£ºLinux¡¢SolarisºÍOpenBSD¡£

¡¡¡¡SSHµÄÖ°Ôð

¡¡¡¡SSH ʹÓÃÇ¿´óµÄ¼ÓÃܹ¦Äܱ£»¤Ô¶³Ì»áÒé²»±»»³ÓжñÒâµÄºÚ¿Í¹¥»÷¡£´ÓʼÖÁÖÕ¶¼Ìṩ¶Ëµ½¶ËµÄ°²È«±£ÕÏ£¬°üÀ¨¿Í»§»úÓëÖ÷»ú½øÐÐÁªÏµ£¬ÒÔ¼°ÔÚµçÄÔÖ®¼ä´«ÊäÓû§ÃûºÍ¿ÚÁî֮ǰ½¨Á¢»áÒéרÓõÄÃÜÂë¼ü½»»»¡£Ëü¿ÉÒÔʹÓöàÖÖ²»Í¬µÄÃÜÂë·½°¸£ºAES¡¢3DES¡¢BlowfishÒÔ¼°ÆäËü·½°¸¡£ÊÜÐÅÈεÄÖ÷»ú¼ø¶¨·½°¸ºÍϵͳ֮¼ä¼üÖµ½»»»Ìá¸ß°²È«ÐÔ£¬OpenSSH²»ÐèÒª°²È«Ö¤Êé»òÓÅÏȼü½»»»¼´¿É´´½¨°²È«¼ÓÃܵÄÔ¶³Ì»áÒé¡£

¡¡¡¡ÁíÍ⣬ʹÓÃSSH¿ÉÒÔ½â¾öijЩÀàÐ͵ÄÍøÂçÓµÈû£¬Ã÷ÏÔ¼ÓËÙÍøÂ磬ÒòΪËüÔÚ´«ÊäÊý¾ÝÇ°ÏȶÔÊý¾Ý½øÐÐÁËѹËõ¡£Ëüͨ¹ýSFTP¼ÓÃÜ£¬ÄÜÌṩÀàËÆÓÚFTPµÄ½»»¥Ê½Îļþ´«ÊäÄÜÁ¦£¬ËùÒÔ£¬ÉõÖÁ¿ÚÁîºÍÓû§ÃûÔÚÍøÂçÉÏ´«Ê䶼ûÓÐ×è°­¡£¶ÔÓÚÎļþ´«Êä²Ù×÷£¬SCPÒ²ÀàËƵØÌṩ°²È«¶ø·½±ãµÄ;¾¶Íê³É´ËÏ×÷----¼ÓÃܵÄÎļþ¿½±´ÃüÁ´ËÃüÁî²Ù×÷ÍøÂçÁ¬½Ó£¬ËüÊÇSSHʵÏÖµÄÒ»²¿·Ý¡£

¡¡¡¡SSHÊǼÓÃܽ»Á÷ÖÐÖÚËùÖÜÖªµÄÍøÂçЭÒé¡£¿ª·¢ËüÊÇΪÁËÈ¡´úRSHЧÓã¬RSHÒ²¼ÓÁËÃÜ£¬µ«ÊDz»¹»°²È«¡£SSH²»½ö¼Ì³ÐÁËRSHµÄ¹¦ÄÜ£¬¶øÇÒÀ©Õ¹¼ÓÇ¿ÁËÆ书ÄÜ£¬ÌرðÊÇ°²È«ÐÔ·½Ãæ¡£

¡¡¡¡LinuxµÄOpenSSH

¡¡¡¡LinuxÉÏ°²×°OpenSSHÊǺÜÈÝÒ׵ġ£ÀýÈ磬ÔÚDebian GNU/LinuxϵͳÉÏ£¬°²×°OpenSSHʱ£¬×öΪ¸ùÓû§µÇ¼£¬È»ºóÊäÈëÃüÁîapt-get install ssh¼´¿É¡£ÀàËƵأ¬ÔÚFedora Core LinuxϵͳÉÏ£¬°²×°OpenSSHʱ£¬×öΪ¸ùÓû§µÇ¼£¬È»ºóÊäÈëÃüÁîyum install ssh¼´¿É¡£ÄãÉõÖÁ²»ÐèÒª×öÕâЩÊÂÇ飬ÒòΪÔÚDebian ºÍFedora CoreÖУ¬ËüÃÇĬÈÏ°²×°ÅäÖÃÖÐÒѾ­°üº¬ÁËOpenSSH¡£¶ÔÓÚLinuxϵͳÀ´Ëµ£¬Èç¹ûҪȷ¶¨ÏµÍ³ÊÇÊÇ·ñÒѾ­°²×°ÁËOoenSSH£¬Ö»ÐèÒªÊäÈëÃüÁ ssh¡£Èç¹ûϵͳÖа²×°ÁËOpenSSH£¬Ôò»á¸ø³ö¼òµ¥µÄʹÓÃÖ¸ÄÏÐÅÏ¢£¨Listing A£©£º

[code]Listing A

$ ssh

usage: ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]

[-D port] [-e escape_char] [-F configfile]

[-iidentity_file] [-L [bind_address:]port:host:hostport]

[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]

[-R [bind_address:]port:host:hostport] [-S ctl_path]

[user@]hostname [command][/code]

¡¡¡¡ÔÚOpenSSH˵Ã÷ÊéÉÏÓиüÍêÕûµÄʹÓÃÐÅÏ¢¡£Õâ¸ö˵Ã÷ÊéÊÇ´«Í³UNIXÎļþÊÖ²áϵͳµÄÒ»²¿·Ö£¬²¢ÇÒÔÚÃüÁîÐÐģʽÏÂÊäÈëman sshÃüÁ¼´¿É·ÃÎÊOpenSSH˵Ã÷Ê顣˵Ã÷ÊéÌṩÁËOpenSSH¿Í»§¶ËÃüÁîÐÐÑ¡ÏîµÄÐÅÏ¢£¬¹ØÁªµÄÅäÖÃÎļþÐÅÏ¢¡¢µ±Ç°°æ±¾ÒÑÖªµÄBugÐÅÏ¢£¬Ó°ÏìÆä²Ù×÷µÄshell»·¾³±äÁ¿ÐÅÏ¢£¬ÒÔ¼°Ïà¹Ø˵Ã÷ÁÐ±í¡£ÕýÈçÁбíËùʾ£¬ÉÏÃæÓÐsshdµÄ˵Ã÷Ê飬ÓÐssh-agentµÄ˵Ã÷Ê飬ÒÔ¼°OpenSSH¹¤¾ß¼¯ÀïÆäËûÓ¦ÓõÄ˵Ã÷Êé¡£

¡¡¡¡ÅäÖò¢Ê¹ÓÃLinux ¿Í»§¶Ë

¡¡¡¡ÔÚOpenSSH¿Í»§¶ËÉÏ£¬´ÓÃüÁîÐзÃÎÊOpenSSH·þÎñÆ÷ÉϵÄÆäËûϵͳʱ£¬½ö½öÖ»ÐèÒªÊäÈëssh hostÃüÁÕâÀï¡°host¡±ÊÇÄ¿±êϵͳµÄÖ÷»úÃû¡£ÓÐʱºòÕâ¸öÖ÷»úÃû²»Äܱ»½âÎö³ÉIPµØÖ·£¬ÒòΪÄãûÓÐÄǸöϵͳµÄDNS£¬²¢ÇÒËüûÓÐÔÚ±¾µØϵͳµÄ/etc/hostsÎļþÖÐÁгöÀ´¡£´ËʱÓбØÒªÖ¸¶¨Ä¿±êϵͳµÄIPµØÖ·¶ø²»ÊÇÖ÷»úÃû£¬ÀýÈ磺ÊäÈëssh 192.168.0.1ÃüÁÁ¬½Ó´ËIP±íʾµÄϵͳ¡£¸ü¶àµÄSSHÃüÁîÈçÏ£º

¡¡¡¡SSHÒ»°ãʹÓö˿Ú22¡£Èç¹ûSSH·þÎñÆ÷ÕìÌýÒ»¸ö²»±ê×¼¶Ë¿Ú£¬Ê¹ÓÃÏÂÃæÃüÁʾÀý¶Ë¿ÚºÅΪ1234£º

[code]ssh -p 1234 host[/code]

¡¡¡¡³ý·ÇÖ¸¶¨ÁËÓû§Ãû£¬·ñÔòËü½«ÊÔͼµÇ¼µ½Ò»¸öÔ¶³Ìϵͳ£¬´ËʱÓû§ÃûÓë±¾µØϵͳÉϵÄÓû§ÃûÏàͬ¡£¿ÉÒÔʹÓÃÃüÁîÑ¡ÏîÖ¸¶¨²»Í¬µÄÓû§Ãû¡£ÏÂÃæ¸ø³öÁËÒ»°ã¸ñʽ£¬¡°user¡±±íʾÓû§Ãû¡£

[code]ssh -l user host[/code]

¡¡¡¡Ò»¸ö¸üÆÕ±éµÄÖ¸¶¨Óû§ÃûµÄ·½·¨ÊÇʹÓÃÏÂÃæµÄ¸ñʽ£º

[code]ssh user@host[/code]

¡¡¡¡Í¨¹ýSSH¶ø²»ÐèÒª´ò¿ªshell½çÃæ¼´¿ÉÒÔÔÚÄ¿±êϵͳÉÏÖ´ÐÐÃüÁî¡£ÏÂÃæÀý×ÓÖеġ°command¡±±íʾÏëÒªÖ´ÐеÄÃüÁ

[code]ssh host command[/code]

¡¡¡¡¿ÉÒÔÔÚÄ¿±êϵͳÉÏÖ¸¶¨µ±Ç°¹¤×÷·¾¶¡£ÔÚÏÂÃæµÄʾÀýÖУ¬Ö¸¶¨ÁË/home/userΪµ±Ç°¹¤×÷·¾¶£º

[code]ssh host:/home/user[/code]

¡¡¡¡¿ÉÒÔ½«ÉÏÃæµÄ¶à¸öÑ¡Ïî×éºÏµ½Ò»¿é£¬Ðγɸü¸´ÔӵĶ¨ÖƲÙ×÷£º

[code]ssh -p 1234 user@host:/home/user

ssh -l user host command[/code]

¡¡¡¡OpenSSHÅäÖÃÎļþλÓÚ·¾¶/etc/sshÏ¡£OpenSSH¿Í»§¶ËÖ÷ÒªµÄÅäÖÃÎļþÔÚ/etc/ssh/ssh_config·¾¶Ï£¬´ó¶àÊý°æ±¾¶¼°üº¬×ã¹»µÄ½âÊÍÐÅÏ¢£¬¸æËßÄãÔõôʹÓÃÅäÖÃÎļþ¡£¶ÔÓÚÓй㷺¶ø¸´ÔÓµÄ˵Ã÷ÊéϵͳµÄ°æ±¾£¬ÀýÈçDebian£¬¿ÉÒÔʹÓÃman ssh_configÃüÁ»ñµÃ×ã¹»¶àµÄOpenSSH¿Í»§¶ËÅäÖÃÐÅÏ¢¡£

¡¡¡¡¶ÔÓÚ°²È«ÐÔ¶øÑÔ£¬Ò»¸öÆÕ±é¶øÖØÒªµÄÅäÖÃÑ¡ÏîÊÇForwardX11£¬ËüÓ¦¸Ã±»ÉèÖóɡ°NO¡±£¬´Ó¶ø×èÖ¹SSH¿Í»§¶ËÏòÍøÂç×Ô¶¯·¢ËÍX WindowsϵͳÐÅÏ¢£¬ÉõÖÁÔÚͨ¹ýSSHÁ¬½Ó¶øûÓÐʹÓÃX Windowsʱ£¬Ò²ÊÇÒ»Ñù¡£Ê¹ÓÃÕâ¸öÉèÖ㬿ÉÒÔÖ¸¶¨Ìض¨µÄSSHÁ¬½Ó£¬Í¨¹ýʹÓÃ- XÃüÁîÑ¡Ï´«ËÍX WindowsϵͳÐÅÏ¢¡£ÔÚetc/ssh/ssh_configÎļþÖÐÆäËüÅäÖÃÑ¡ÏîÒ²ÄÜÖ´Ðкͷþ´Ó°²È«Õþ²ß£¬²¢ÇÒ¿ÉÒÔ·þÎñÓÚÌØÊâµÄ°²È«ÐèÒª¡£

¡¡¡¡»ùWindowsµÄSSH¿Í»§¶Ë

¡¡¡¡Î¢ÈíµÄWindowϵͳÓкܶàSSH¿Í»§¶Ë³ÌÐò£¬ÓÐЩÊÇ˽È˵ġ¢ÉÌÒµµÄÓ¦ÓóÌÐò£¬ÓÐЩÊÇÃâ·ÑÈí¼þ»ò¹²ÏíÈí¼þ£¬»¹ÓÐһЩÊÇ¿ªÔ´Èí¼þ£¬ÀýÈ磺OpenSSH¡£´æÔÚÃüÁîÐпͻ§¶Ë³ÌÐòʱ£¬ËüÃÇÖ®ÖÐÓÐЩ³ÌÐò±»°²×°³ÉΪÀàËÆUNIX shellµÄÒ»²¿·Ö£¬ÏÖÔÚ×î³£ÓÃSSHµÄͼÐÎÓû§½çÃæ³ÌÐò¡£ËüÃÇÖ®ÖУ¬WinSCPÓÃÓÚSCPºÍSFTPÐÔÄÜ£¬PuTTYÓÃÓÚSSHshellÐÔÄÜ¡£Í¨¹ýÔĶÁÉÏÊöµÄ¹ØÓÚLinuxµÄOpenSSHʹÓÃÐÅÏ¢£¬ÔòºÜÈÝÒ×Á˽âWinSCPºÍPuTTYµÄÓû§½çÃæºÍËüÃǵÄÅäÖ᣻¹¿ÉÒÔ»ñµÃ³ÆΪOpenSSH for Windows΢ÈíWindows OpenSSHµÄʵ¼Ê¶Ë¿Ú¡£

¡¡¡¡ÅäÖò¢Ê¹ÓÃLinux·þÎñÆ÷

¡¡¡¡Ò»°ãµØ£¬OpenSSH·þÎñÆ÷ÔËÐÐLiunxϵͳ¡£Ëü¿ÉÒÔÔÚDebian GNU/LinuxϵͳÖÐͨ¹ý/etc/init.d/sshÃüÁî½øÐÐÖØÆô¡£ÏàËƵأ¬ÔÚÆô¶¯ºÍֹͣʱ£¬Ö»ÐèÒª½«¡°restart¡±Öû»³É¡°start¡±¡°stop¡±¼´¿É¡£Fedora Core LinuxϵͳʹÓÃÏàͬµÄÃüÁî¸ñʽ£¬µ«ÊÇÐèÒª½«/etc/init.d/sshÖеġ°ssh¡±Öû»³É¡°sshd¡±¡£

¡¡¡¡ÓëOpenSSH¿Í»§¶ËÅäÖÃÎļþÏàËÆ£¬OpenSSH·þÎñÆ÷ÅäÖÿÉÒÔͨ¹ý/etc/ssh/sshd_configÎļþÍê³É¡£ËüµÄ¸ñʽÓë/etc/ssh/ssh_config·Ç³£ÏàËÆ£¬µ«ÊÇÆäÑ¡ÏîÓкܶ಻ͬ¡£ÅäÖÃϸ½Ú¿ÉÒÔͨ¹ýÊäÈëman sshd_configÃüÁî²é¿´¡£

¡¡¡¡Ò»°ã½«UsePrivilegeSeparationºÍIgnoreRhostsÑ¡ÏîÉèÖóɡ°YES¡±£¬¶ø½«PermitRootLoginºÍPermitEmptyPasswordsÑ¡ÏîÉèÖóɡ°NO¡±¡£ÓëOpenSSH¿Í»§¶ËÒ»Ñù£¬Ê¹ÓÃSSH´«ÊäX WindowsϵͳÐÅÏ¢µÄ·çÏշdz£µÍ£¬Èç¹ûûÓбØÒª£¬¶ÔÈκÎϵͳËü¶¼Ó¦¸ÃÊDz»»î¶¯µÄ¡£ÕâÑù£¬Í¨³£½«X11ForwardingÉèÖóɡ°NO¡±¡£

¡¡¡¡ÔÚLinuxÉÏ£¬ËüÃÇͨ³£ÓÐÏ൱¾ßÓа²È«ÒâʶµÄÈ˽øÐÐά»¤£¬ÕâЩÅäÖÃÑ¡ÏîÓ¦¸Ã½øÐÐÇ¡µ±ÅäÖá£Ò»°ãÓ¦¸Ã°üÀ¨PermitRootLoginºÍX11ForwardingÅäÖÃÑ¡Ïî¡£

¡¡¡¡Ê¹ÓÃOpenSSH

¡¡¡¡OpenSSH»¹ÓÐÁíÍ⹦ÄÜ¡£ÀýÈ磺ÆäËûÍøÂçЭÒé¿ÉÒÔÔÚOpenSSHЭÒéÉÏ¡°´òËíµÀ¡±£¬´Ó¶øÌṩ¸ü¸ßµÄ°²È«ÐÔ£¬ÕâÒÑÔÚ±¾ÎÄÖÐÓÐËùÌáʾ¡£ssh-agent¹¤¾ß¿ÉÒÔ¼ò»¯OpenSSH¿Í»§¶ËµÄ¹ÜÀíºÍʹÓ᣻¹ÓÐһЩ²»Ïà¹ØµÄ¹¤¾ß£¬°üÀ¨SSHËíµÀÖ§³Ö£¬ÀýÈ磺Subversion°æ±¾¿ØÖÆϵͳ¡£ËüµÄDZÄÜÊÇÎÞÇµÄ£¬²»¿ÉÄÜÕÒµ½ËüÃǵÄÖյ㡣

¡¡¡¡Ê¹Óöą̀µçÄÔµÄLinuxÐÂÓû§£¬¿ÉÄܲ»»áÒ»ÏÂ×ÓÁ˽âSSHµÄ¼ÛÖµ¡£ËûÃǶ¼Ï°¹ßÓÚ΢ÈíµÄWindows²Ù×÷£¬ WindowsÉϵĽçÃæÒѾ­ÓÅ»¯ºÃÁË£¬ÔÚijÖ̶ֳÈÉÏ£¬·´¶ø²»Ò×ÓÚ½øÐÐÔ¶³Ì¹ÜÀí¡£¼´ËãÓзþÎñÆ÷¹ÜÀíºÍÔ¶³Ì¼¼ÊõÖ§³Ö£¬Ê¹ÓÃÖîÈçWindows Remote DesktopºÍTerminal Services for WindowsµÈÔ¶³Ì¹ÜÀí¹¤¾ß£¬ÆäÓÐЧÐÔÒ²Ï൱ÓÐÏÞ£¬²¢ÇÒ²»¹ÄÀøͨ¹ýÍøÂçÖ±½ÓʹÓÃWindows×ÊÔ´¡£

¡¡¡¡Ïà·´£¬LinuxÓû§ÔÚµ¥¸öϵͳÉÏÔËÐÐËûÃǵÄÈÕ³£³ÌÐò£¬²¢ÇÒÔÚµçÄÔÉϾ­¹ý¼òµ¥°²×°¾ÍÄÜͨ¹ýSSH·ÃÎÊÕâЩ³ÌÐò¡£ºÜ¶à Linux¹ÜÀíÔ±½«×øÔÚһ̨µçÄÔÇ°Ã棬Íê³É²»ÔÚͬһ¸öµØ·½µÄ¶ą̀µçÄÔÉϵŤ×÷£¬°üÀ¨email¡¢Ð´×÷¡¢±à³Ì£¬Õâ²»ÊÇÒ»Á½¸öÍøÂçÓ¦ÓóÌÐò¡£¶ÔSSHµÄÐÔÄÜÔ½ÊìϤ£¬ÔòÆäÓô¦Ô½´ó£¬Í¬Ê±Ò²Ô½ÐÅÈÎËü¡£µ«ÊÇ´ÓWindowsÖÐ×ß³öÀ´µÄLinuxÓû§»¹²»ÄÜÁ¢¼´¸ÐÊܵ½SSHÍƶ¯Éú²úÁ¦µÄÄÜÁ¦¡£

¡¡¡¡OpenSSHµÄÅäÖúÍʹÓÃÊÇÖµµÃѧϰµÄ£¬¼´Ê¹ÄãÏÖÔÚ²»ÄÜÁ¢¼´¿´³öÆä×÷Ó㬼ÙÒÔʱÈÕ£¬Äã»áÀë²»¿ªËüµÄ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ