windows下開啟ssh服務(wù)

OpenSSH的安裝及運(yùn)行

使用powershell安裝openSSH

以管理員身份運(yùn)行powershell唾琼,運(yùn)行以下指令:

 Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'                       

已安裝的服務(wù)輸出 "Installed",未安裝輸出"NotPresent"匣砖,如下:

根據(jù)需要安裝的組件運(yùn)行以下命令:

# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

如安裝成功帮匾,控制臺將輸出以下內(nèi)容:

Path          :
Online        : True
RestartNeeded : False

重啟電腦添加服務(wù)偏灿,啟動并配置OpenSSH服務(wù)

管理員身份運(yùn)行powershell扣蜻,然后運(yùn)行以下命令啟動sshd service:

# Start the sshd service
Start-Service sshd

# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

客戶機(jī)登錄測試(此部分運(yùn)行在客戶機(jī)),此部分過于簡單尺棋,不做詳細(xì)演示

ssh username@ip
#輸入密碼

在服務(wù)器上部署rsa密鑰

客戶機(jī)生成密鑰(此部分運(yùn)行在客戶機(jī))

ssh-keygen -t rsa
#一路enter

此時客戶機(jī)目錄 ~/.ssh下將生成id_rsa和id_rsa.pub封锉,將id_rsa.pub改名為administrators_authorized_keys,粘貼至服務(wù)器的C:\ProgramData\ssh目錄

修改服務(wù)器的ssh配置文件

#目錄C:\ProgramData\ssh\sshd_config

內(nèi)容如下

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m

RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes

#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile  .ssh/authorized_keys

#AuthorizedPrincipalsFile none

# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no

# GSSAPI options
#GSSAPIAuthentication no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem   sftp    sftp-server.exe

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   AllowTcpForwarding no
#   PermitTTY no
#   ForceCommand cvs server

Match Group administrators
       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

管理員身份運(yùn)行powershell膘螟,提升文件administrators_authorized_keys權(quán)限

icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"    

客戶機(jī)以rsa連接服務(wù)器

ssh -i ~\.ssh\id_rsa username@ip
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末成福,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子荆残,更是在濱河造成了極大的恐慌奴艾,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件内斯,死亡現(xiàn)場離奇詭異蕴潦,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)俘闯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進(jìn)店門潭苞,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人真朗,你說我怎么就攤上這事此疹。” “怎么了遮婶?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵蝗碎,是天一觀的道長。 經(jīng)常有香客問我旗扑,道長蹦骑,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任肩豁,我火速辦了婚禮脊串,結(jié)果婚禮上辫呻,老公的妹妹穿的比我還像新娘清钥。我一直安慰自己琼锋,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布祟昭。 她就那樣靜靜地躺著缕坎,像睡著了一般。 火紅的嫁衣襯著肌膚如雪篡悟。 梳的紋絲不亂的頭發(fā)上谜叹,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機(jī)與錄音搬葬,去河邊找鬼荷腊。 笑死,一個胖子當(dāng)著我的面吹牛急凰,可吹牛的內(nèi)容都是我干的女仰。 我是一名探鬼主播,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼抡锈,長吁一口氣:“原來是場噩夢啊……” “哼疾忍!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起床三,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤一罩,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后撇簿,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體聂渊,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年四瘫,在試婚紗的時候發(fā)現(xiàn)自己被綠了歧沪。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡莲组,死狀恐怖诊胞,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情锹杈,我是刑警寧澤撵孤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站竭望,受9級特大地震影響邪码,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜咬清,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一闭专、第九天 我趴在偏房一處隱蔽的房頂上張望奴潘。 院中可真熱鬧,春花似錦影钉、人聲如沸画髓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽奈虾。三九已至,卻和暖如春廉赔,著一層夾襖步出監(jiān)牢的瞬間肉微,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工蜡塌, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留碉纳,地道東北人。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓馏艾,卻偏偏與公主長得像劳曹,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子攒至,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容