在windows下安装和使用openssh

本文可自由转载,但请遵循“署名-非商业用途-保持一致”的创作共用协议。 永久链接:JoeCen's 小猫窝
-----------------------------

每天都在公司使用putty来运行ssh client连接linux,今天记得好像在windows中也可以安装openssh server,那么就不用再开一个软件,而且还可以使用sftp和scp了。于是决定试试。

1、下载openssh。
可以在此下载

2、安装。
安装很简单,就像其它windows下的软件一样,双击即可。安装到大半,会有提示框弹出,说“必须要设置../etc/passwd文件才可以正常运作 openssh,详情可以参阅readme.txt或quickstart.txt文件。”不用管它,按确定继续完成安装。安装完后可以看到 quickstart.txt文件的内容。

3、配置。

第一、打开一个ms-dos终端,进入openssh/bin目录。(安装完openssh后,发现多了几个在linux中常用的命令,如:ls、mkdir、rm、chmod、chown等,很有亲切感!

第二、将计算机上的组导入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 ] >> ..\etc\passwd 这是加入本地用户的命令。
mkpasswd -d [-u ] >> ..\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 ] >> ..\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中更改。

呵呵,这样在windows和linux之间传文件就很简单了。

随机日志

  • 为网易自豪一次
  • 廉价航空与安全
  • 如何将cacti的取样间隔(polling interval)更改为一分钟?
  • 对google,只能说好啦!
  • 使用OpenVPN实现网通、电信机房间快速、安全通信
  • One Response to “在windows下安装和使用openssh”

    1. Eric Tsai Says:

      你也可以參考看看這篇喔:Run OpenSSH sshd on Windows without Cygwin

    Leave a Reply