cygwin安装sshd服务并实现无密码登录

http://blog.csdn.net/cybercode/article/details/7080743

这篇文章主要是为我在win7(64位)下搭建hadoop环境所准备的。首先参照在cygwin使用总结这篇文章在cygwin中安装所必须得软件包,然后如下进行操作:

[plain] view plaincopy
 
  1. sony@sony-VAIO~ $ ssh-host-config  
  2.   
  3. *** Info: Generating /etc/ssh_host_key  
  4. *** Info: Generating /etc/ssh_host_rsa_key  
  5. *** Info: Generating /etc/ssh_host_dsa_key  
  6. *** Info: Generating /etc/ssh_host_ecdsa_key  
  7. *** Info: Creating default /etc/ssh_config file  
  8. *** Info: Creating default /etc/sshd_config file  
  9. *** Info: Privilege separation is set to yes by default since OpenSSH 3.3.  
  10. *** Info: However, this requires a non-privileged account called ‘sshd‘.  
  11. *** Info: For more info on privilege separation read /usr/share/doc/openssh/READ  
  12. ME.privsep.  
  13. *** Query: Should privilege separation be used? (yes/no) no  
  14. *** Info: Updating /etc/sshd_config file  
  15.   
  16. *** Query: Do you want to install sshd as a service?  
  17. *** Query: (Say "no" if it is already installed as a service) (yes/no) yes  
  18. *** Query: Enter the value of CYGWIN for the daemon: netsec] netsec  
  19. *** Info: On Windows Server 2003, Windows Vista, and above, the  
  20. *** Info: SYSTEM account cannot setuid to other users -- a capability  
  21. *** Info: sshd requires.  You need to have or to create a privileged  
  22. *** Info: account.  This script will help you do so.  
  23.   
  24. *** Info: You appear to be running Windows XP 64bit, Windows 2003 Server,  
  25. *** Info: or later.  On these systems, it‘s not possible to use the LocalSystem  
  26. *** Info: account for services that can change the user id without an  
  27. *** Info: explicit password (such as passwordless logins [e.g. public key  
  28. *** Info: authentication] via sshd).  
  29.   
  30. *** Info: If you want to enable that functionality, it‘s required to create  
  31. *** Info: a new account with special privileges (unless a similar account  
  32. *** Info: already exists). This account is then used to run these special  
  33. *** Info: servers.  
  34.   
  35. *** Info: Note that creating a new user requires that the current account  
  36. *** Info: have Administrator privileges itself.  
  37.   
  38. *** Info: No privileged account could be found.  
  39.   
  40. *** Info: This script plans to use ‘cyg_server‘.  
  41. *** Info: ‘cyg_server‘ will only be used by registered services.  
  42. *** Query: Do you want to use a different name? (yes/no) yes  
  43. *** Query: Enter the new user name: sony  
  44. *** Query: Reenter: sony  
  45.   
  46. *** Warning: Privileged account ‘sony‘ was specified,  
  47. *** Warning: but it does not have the necessary privileges.  
  48. *** Warning: Continuing, but will probably use a different account.  
  49. *** Warning: The specified account ‘sony‘ does not have the  
  50. *** Warning: required permissions or group memberships. This may  
  51. *** Warning: cause problems if not corrected; continuing...  
  52. *** Query: Please enter the password for user ‘sony‘:  
  53. *** Query: Reenter:  
  54.   
  55.   
  56. *** Info: The sshd service has been installed under the ‘sony‘  
  57. *** Info: account.  To start the service now, call `net start sshd‘ or  
  58. *** Info: `cygrunsrv -S sshd‘.  Otherwise, it will start automatically  
  59. *** Info: after the next reboot.  
  60.   
  61. *** Info: Host configuration finished. Have fun!  

 $ net start sshd
发生系统错误 1069 --- 表示由于登录失败而无法启动服务

解决方法:在cmd中输入services.msc即可打开windows的服务,在服务中把密码改对就可以了。
(在上面配置ssh的过程中我的用户名是:sony 密码是:123456)

sshd服务装成功如下:

[plain] view plaincopy
 
  1. sony@sony-VAIO ~ $ net start sshd  
  2. CYGWIN sshd 服务正在启动 .  
  3. CYGWIN sshd 服务已经启动成功  

接下来是配置无密码登陆:

[plain] view plaincopy
 
  1. sony@sony-VAIO ~ $ ssh-keygen -t rsa  
  2. Generating public/private rsa key pair.  
  3. Enter file in which to save the key (/home/sony/.ssh/id_rsa):  
  4. Created directory ‘/home/sony/.ssh‘.  
  5. Enter passphrase (empty for no passphrase):  
  6. Enter same passphrase again:  
  7. Your identification has been saved in /home/sony/.ssh/id_rsa.  
  8. Your public key has been saved in /home/sony/.ssh/id_rsa.pub.  
  9. The key fingerprint is:  
  10. e8:38:5e:e3:bb:cf:76:03:61:5f:f2:68:ed:a3:49:db sony@sony-VAIO  
  11. The key‘s randomart image is:  
  12. +--[ RSA 2048]----+  
  13. |                 |  
  14. |                 |  
  15. |                 |  
  16. |       .o . .    |  
  17. |      ..So *     |  
  18. |     o  . + o    |  
  19. |    o +  o..     |  
  20. |   . + o..o+o    |  
  21. |    . +=o.+oE.   |  
  22. +-----------------+  
  23.   
  24. sony@sony-VAIO ~ $ cd .ssh/  
  25.   
  26. sony@sony-VAIO ~/.ssh $ ls  
  27. id_rsa  id_rsa.pub  
  28.   
  29. sony@sony-VAIO ~/.ssh $ cp id_rsa.pub authorized_keys  
  30.   
  31. sony@sony-VAIO ~/.ssh $ ls  
  32. authorized_keys  id_rsa  id_rsa.pub  

验证如下:

[plain] view plaincopy
 
    1. sony@sony-VAIO ~/.ssh $ ssh localhost  
    2. The authenticity of host ‘localhost (::1)‘ can‘t be established.  
    3. ECDSA key fingerprint is 5f:21:b1:24:80:92:f6:af:3e:e3:a8:f9:cb:a4:4f:ec.  
    4. Are you sure you want to continue connecting (yes/no)? yes  
    5. Warning: Permanently added ‘localhost‘ (ECDSA) to the list of known hosts.  
    6.   
    7. sony@sony-VAIO ~ $ who  
    8. sony     tty0         2011-11-25 15:42 (::1) 

cygwin安装sshd服务并实现无密码登录

上一篇:SpringBoot 自动配置原理


下一篇:SpringBoot的自动装配原理