windows sshd powershell 配置

安装sshd
打开“设置”,选择“应用”>“应用和功能”,然后选择“可选功能” 。
扫描列表,查看是否已安装 OpenSSH。 如果未安装,请在页面顶部选择“添加功能”,然后:
查找“OpenSSH 客户端”,再单击“安装”
查找“OpenSSH 服务器”,再单击“安装”

开启sshd服务
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

免密登录
服务端切换到C:\ProgramData\ssh\下(首次启动sshd后会生成该文件夹),打开sshd_config文件,
修改文件(以下是重点):

确保以下3条没有被注释
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no

确保以下2条有注释掉 重点,这两行要注释
#Match Group administrators
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

相关命令:
查看状态:Get-Service sshd
关闭服务:Stop-Service sshd
重启服务:Restart-Service sshd

为 Win10 的 OpenSSH 配置默认 shell
先确认 OpenSSH 默认安装位置是:C:Windows\System32\openssh 。
cmd 中 path 和 PowerShell 中 $env:path 可以显示当前路径。
在 PowerShell 中用以下命令将默认 shell 设为 PowerShell:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

powerShell 配置 

安装需要的软件
Install-Module -AllowClobber Get-ChildItemColor

choco install ntop.portable

查看profile
$PROFILE

编辑profile 内容如下

set-alias vi "C:/Program Files (x86)/Vim/vim82/./vim.exe"
set-alias git "C:/Program Files/Git/bin/./git.exe"

set-alias top "C:/ProgramData/chocolatey/bin/ntop.exe"

Import-Module PSReadLine
If (-Not (Test-Path Variable:PSise)) {
  # Only run this in the console and not in the ISE
  Import-Module Get-ChildItemColor
  Set-Alias l Get-ChildItem -option AllScope
  Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
}


# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

New-Alias open invoke-item
New-Alias which get-command

 

引用链接
https://zhuanlan.zhihu.com/p/356463854
https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse
https://www.cnblogs.com/deepinnet/p/15228378.html
https://ld246.com/article/1598698273711

posted @ 2021-12-30 00:05  boybai  阅读(1367)  评论(0编辑  收藏  举报