OpenSSH for Windows 配置

来源:互联网 发布:网络传真机怎么拨号 编辑:程序博客网 时间:2024/06/06 10:44

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


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       这是加入域用户的命令。

     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/。

0 0