Windows 终端配置及美化
目录
安装 powershell-7
安装配置 oh-my-posh
设置 PS 执行策略
警告
需要以管理员的身份运行 powershell
# 查询当前的执行策略
Get-ExecutionPolicy -List
# 修改执行策略(以管理员身份打开powershell)
Set-ExecutionPolicy RemoteSigned -Scope Process
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine下载终端字体
安装 oh-my-posh
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))安装插件库
# 图标库:支持文件图标
Install-Module -Name Terminal-Icons -Repository PSGallery
# posh-git:支持git信息显示
Install-Module posh-git
# 快速跳转目录
Install-Module ZLocation
# 安装命令提示插件
Install-Module PSReadLine配置主题
创建配置文件
# 配置文件位置:C:\Users\\[当前用户名]\Documents\WindowsPowerShell
New-Item -Path $PROFILE -Type File -Force编辑配置文件 notepad $PROFILE
# 禁止检查更新
oh-my-posh disable notice
# 主题设置
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\amro.omp.json" | Invoke-Expression
# 导入插件
Import-Module Terminal-Icons
Import-Module posh-git
Import-Module PSReadLine
Import-Module ZLocationwindows terminal 设置
将 powershell-7 设置为默认终端,更换默认字体为 MesloLGS NF

设置终端窗口大小,位置
"initialCols": 80, // 窗口宽
"initialRows": 20, // 窗口高
"initialPosition": "10,10", // 设置窗口默认打开位置powershell 设置别名
编辑配置文件:
notepad $PROFILE若没有该配置文件,则创建
New-Item -Path $PROFILE -Type File -Force在配置文件中添加
function alias{your command}安装配置 scoop 包管理器
安装
iex "& {$(irm scoop.201704.xyz)} -RunAsAdmin"换源
# 更换scoop的repo地址
scoop config SCOOP_REPO "https://gitee.com/scoop-installer/scoop"
# 拉取新库地址
scoop update安装插件
# 让 powershell 支持 liunx 常用命令
scoop install busybox
# 让 powershell 支持 sudo 切换管理员权限
scoop install sudo配置 SSH
添加 SSH 服务
“设置” —> “系统” —> “可选功能” —> “查看功能”,搜索 openssh,安装即可。
SSH 服务启停
# 查看安装状态
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# 查看启停状态
Get-Service -Name sshd
# 设置 SSHD 服务自动启动
Set-Service -Name sshd -StartupType 'Automatic'
# 启动服务
Start-Service sshd
# 重启服务
Restart-Service sshd修改 SSH 配置文件
文件位置:C:\ProgramData\ssh\sshd_config
# Match Group administrators
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
# 允许管理员登录
PermitRootLogin yes
# 允许免密
PubkeyAuthentication yes
# 允许密码
PasswordAuthentication yes
# 允许空密码
PermitEmptyPasswords no
# authorized_keys 位置
AuthorizedKeysFile .ssh/authorized_keys设置免密登录到 Windows
- 将公钥复制到 C:\Users\Administrator.ssh\authorized_keys 文件
- 重启 ssh 服务
设置 SSH 默认登录终端为 powershell-7
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force