安装PowerShell
安装PowerShell帮助文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo add-apt-repository universe
sudo apt-get install -y powershell
pwsh
|
通过 SSH 进行 PowerShell 远程处理
通过 SSH 进行 PowerShell 远程处理
1 2 3 4 5 6 7 8 9 10 11 12
| sudo apt install openssh-client sudo apt install openssh-server
PasswordAuthentication yes
Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile
PubkeyAuthentication yes
|
重启 sshd 服务
1
| sudo service sshd restart
|
通过PowerShell 连接 Ubuntu
通过PowerShell 连接 Ubuntu
1
| New-PSSession -HostName UserA@LinuxServer01
|

PowerShell使用密钥文件连接Ubuntu
1.先在Windows打开PowerShell输入ssh-keygen.exe生成公/私密钥

2.把公钥复制到Ubuntu

1 2 3 4 5 6 7 8
| $session=New-PSSession -HostName 10.76.20.51 -UserName giant
Copy-Item "C:\Users\Administrator\id_rsa.pub" -Destination "/home/giant/.ssh/hncsie-liuju.pub" -ToSession $session
Enter-PSSession -Session $session cd ./.ssh ls
|
3.修改Ubuntu SSH配置
#打开RSA认证
RSAAuthentication yes
#公钥认证
pubkeyAuthentication yes
#Root权限登录
permitROOTlogin yes
#添加公钥文件
AuthorizedKeysFile .ssh/hncsie-liuju.pub

4.重启sshd服务sudo service sshd restart
1 2 3 4
| sudo vi /etc/ssh/sshd_config
sudo service sshd restart
|

1 2 3 4
| $session=New-PSSession -HostName 10.76.20.51 -UserName giant -KeyFilePath .\id_rsa
Enter-PSSession -Session $session
|
参考文档
sshd.exe,它是远程所管理的系统上必须运行的 SSH 服务器组件
ssh.exe,它是在用户的本地系统上运行的 SSH 客户端组件
ssh-keygen.exe,为 SSH 生成、管理和转换身份验证密钥
ssh-agent.exe,存储用于公钥身份验证的私钥
ssh-add.exe,将私钥添加到服务器允许的列表中
ssh-keyscan.exe,帮助从许多主机收集公用 SSH 主机密钥
sftp.exe,这是提供安全文件传输协议的服务,通过 SSH 运行
scp.exe 是在 SSH 上运行的文件复制实用工具