OpenSSH for Windows 配置

來源:互聯網
上載者:User

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、安裝完後產生group和passwd檔案後就可以進行簡的ssh操作了

 i. 產生group和passwd檔案(註:參數-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/。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.