OpenSSH for Windows 配置

1.      下载openssh并安装。

http://www.mls-software.com/opensshd.html

  1. New Version

    OpenSSH 6.6.1p1-3
    This is an update to the latest OpenSSH 6.6.1p1-3 and OpenSSL 1.0.1.h-1. The largest change is the combination of the 32 and 64 bit installations into a single binary - making maintenance easier for me. There are also a number of small bug fixes/feature requests in this version per user requests.
    1. Allow user requested key size during install
    2. Added support for silent installs: /S /CLIENTONLY=1 or /SERVERONLY=1
    3. Fixed uninstaller to support silent uninstalls
    4. Fixed how home diretory is stored in registry
    5. Fixed uninstall bug in resetting the PATH - handling case where OpenSSH was in the middle of the path
    6. This is a new build (7/26/2014) - nothing changed except it was built to support string lengths of 8192 (fixing a bug someone ran into with a very large path). If this worked OK for you and didn't corrupt your path, no need to re-download this rebuild.

    VersionWindows x86Windows x64
    OpenSSH 6.6.1p1-3
    setupssh-6.6.1p1-3.exe     new.jpg
    SHA1=6af0c09ce98b0fe1

安装很简单,就像其它windows下的软件一样,双击即可。

netstat -an 可以看到port 22 listen


2.  配置。 

     第一、打开一个ms-dos终端,进入openssh/bin目录。

     第二、将计算机上的组导入group文件中。这里分两种情况,第一种是本地,第二种是在域中。分别运行-l和-d参数。如果想将两种组都导入,可以先运行-l的参数再运行-d参数的命令。 
下面是原文: 
Use mkgroup to create a group permissions file. For local groups, use the "-l" switch. For domain groups, use the "-d" switch. 
     For both domain and local, it is best to run the command twice (remember to use >>, not >). If you use both, make sure to edit the file to remove any duplicate entires. 
       mkgroup -l >> ..\etc\group         这是加入本地组的命令。 
       mkgroup -d >> ..\etc\group       这是加入域组的命令。 
     (注意执行位置的路径)
     第三、 将计算机的用户与其密码导入passwd文件中。与上面的组一样,也是分本地和域两种情况。如果没有该文件或没有导入用户的信息。作为server的话,将不能被登陆。 
下面是原文: 
Use mkpasswd to add authorized users into the passwd file. For local users, use the "-l" switch. For domain users, use the "-d" switch. 
     For both domain and local, it is best to run the command twice (remember to use >>, not >). If you use both, make sure to edit the file to remove any duplicate entires. 

       mkpasswd -l [-u <username>] >> ..\etc\passwd       这是加入本地用户的命令。 
       mkpasswd -d [-u <username>] >> ..\etc\passwd       这是加入域用户的命令。 

这里举例 我新建了个root管理员用户 密码随便运行mkpasswd -l -u root >> ..\etc\passwd就可以了,用ssh工具就可以连接


     NOTE: To add users from a domain that is not the primary domain of the machine, add the domain name after the user name. 
     NOTE: Ommitting the username switch adds ALL users from the machine or domain, including service accounts and the Guest account. 

       如果计算机没有域,只要运行两条命令就可以了。(注意我是在openssh/bin目录下运行的。)

   mkgroup -l >> ..\etc\group         
   mkpasswd -l [-u <username>] >> ..\etc\passwd


4.启动openssh server。 
       net start opensshd 
很明显,停止opensshd服务的命令就是: 
     net stop opensshd 
5、使用。 
 ssh -p 端口 用户名@对方主机IP 
sftp -p 端口 用户名@对方主机IP 
scp -p 端口 用户名@对方主机IP:文件路径 . 注意:端口默认是22,所以一般不用加-p参数。要更改端口可以在etc/sshd_config中更改。

 

2 安装完后生成grouppasswd文件后就可以进行简的ssh操作了

 i. 生成grouppasswd文件(注:参数-l 为本机 –d 为域 –u username 为本地/域用户名)

cd d:\svn\openssh

mkgroup -l >> etc\group

mkpasswd -l >> etc\passwd

 ii.              启用服务

                                    启用停止服务命令:

                                     启用:net start opensshd

                                     停止:net stop opensshd

iii.              以上两个步骤完成后就可以SSH命令访问ssh服务器了

         在命令行窗口输入ssh 用户名@机器名 登录服务器,我在本机登录,输入命

ssh Administrator@localhost

使用ssh首次连接一个远程ssh服务器时,会出现类似下边的信息。

   The authenticity of host '10.0.0.1' can't be established.

  RSA key fingerprint is c6:d4:e7:23:03:ce:15:2c:08:ec:39:7e:52:29:a5:a6.

  Are you sure you want to continue connecting (yes/no)? yes

这是因为ssh不能识别这台主机,键入yes将会把这台服务器的信息写入 /.ssh/known_hosts文件,下次连入这台远程服务器时就不会出现这类信息。

 在windows的机器上可能还会出现以下提示:Could not create directory '/home/Administrator/.ssh'. 这是由于目录/home/Administrator/.ssh不存在造成的,在下面的设置里,将会更改/home目录位置并创建用户目录

3 设置 /home (根目录):

  在Windows 2000 and XP中,/home默认是在C:\Documents and Settings;在Windows NT 4.0中,/home默认是在C:\WINNT\Profiles,但我安装完查看注册表,/home目录的默认值却为” C:\Documents and Settings\Administrator\「开始」菜

 修改注册表,把它改为D:\svn\openssh\home

[HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/home]

"native"="D:\\svn\\OpenSSH\\home"

"flags"=dword:0000000a

"native" 改成你自己的/home所在目录,此目录就是默认的登陆目录,比如用户名:Administrator那你进入的目录是/home/Administrator(注:更改目录后要建立对应的目录,并且用户名的目录也要创建)

为了配合上面更改,还得做一些工作:在D:\svn\OpenSSH目录上创建home目录、用户目录(以administrator用户为例)

cd D:\svn\OpenSSH

md home

md home\Administrator

md home\Administrator\.ssh

 

4 重启服务器,检查配置后运行是否正常

5、 进阶:设置基于密钥认证的方式访问,上面的配置登录是使用用户名、密码方式访问,安全度较弱,如果想要更高的安全度,可以采用基于密钥的安全认证。

配置OpenSSH for Windows为密钥认证的步骤:
----------------------------------------------------------
1. 创建一个Windows用户ssh专用来SSH远程登陆。
可以在本地安全策略中设置禁止ssh本地登陆,不过这样以来单机调试就不方便了。
----------------------------------------------------------
2. 生成用户信息。这里是生成了所有用户的信息,当然只指定用户ssh也行
.\bin\mkgroup -l >> .\etc\group
.\bin\mkgroup -d >> .\etc\group
.\bin\mkpasswd -l >> .\etc\passwd
.\bin\mkpasswd -d >> .\etc\passwd
----------------------------------------------------------
3. 生成用户ssh的home目录
mkdir home
cd home
mkdir ssh
cd ssh
mkdir .ssh
----------------------------------------------------------
4. 修改cygwin环境默认的home目录
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/home]
"native"="C:\\Program Files\\OpenSSH\\home"
"flags"=dword:0000000a
----------------------------------------------------------
5. 生成密钥
cd bin
mkdir keys
ssh-keygen -t rsa -b 2048 -f keys\rsa2048 -C "This is passphrase hint" -N "This is passphrase"
mkdir keys\.ssh
cat rsa2048.pub > keys\.ssh\authorized_keys
----------------------------------------------------------
6. 将上面生成私转为SSH客户端可使用格式,这里用PuTTY,可用PuTTYgen转为PuTTY用的PPK格式
----------------------------------------------------------
7. 将OpenSSH设置为只接受密钥认证。
这里额外开了sftp服务。另外,StrictModes no选项将告诉OpenSSH不检查用户ssh的home目录的权限设置
Protocol 2
Port 22
HostKey /etc/ssh_host_rsa_key
PermitRootLogin no
PermitEmptyPasswords no
StrictModes no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#IgnoreUserKnownHosts yes
PasswordAuthentication no
UsePAM no
UsePrivilegeSeparation no
MaxStartups 10:30:60
Subsystem sftp /usr/sbin/sftp-server
----------------------------------------------------------
8. 设置路由器NAT和软件防火墙
NAT设置了映射22号端口的TCP包。
软件防火墙设置允许C:\Program Files\OpenSSH\usr\sbin\sshd.exe侦听TCP port 22。
----------------------------------------------------------
9. 基本上差不多了,要启用或停止OpenSSH服务可
net start opensshd
net stop opensshd
在services.msc里启用或停止也可
----------------------------------------------------------
10. PuTTY作中端还不错,就是中文不好办。
要sftp的话,用WinSCP和FileZilla都行。
WinSCP和FileZilla看及进入中文目录名/文件名都没问题,但拷贝等操作报服务端找不到文件错误,
也许和OpenSSH for Windows带的sftp-server.exe版本低了有关吧(3.x的样子)
注意cygwin环境下将Windows各磁盘映射为/cygdrive/。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值