powershell下ssh客户端套件实现
2023-09-14 08:56:56 时间
有时会需要和Linux机器进行交互。所以这时就需要在Powershell中使用SSH。
0x01 查找Powershell中的SSH功能模块
如图,显示没有find-module的命令,需要安装PackageManagement:
下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=51451
0x02 安装、使用SSH模块
A) Posh-SSH
Install-Module -Name Posh-SSH 安装Posh-SSH
可以通过下面的命令,查看安装的模块包含什么命令:
get-command -Module posh-ssh
在PowerShell中使用SSH
添加SSH会话命令:
New-SSHSession -ComputerName "192.168.190.148" -Credential (Get-Credential root)
获取SSH会话命令:
Get-SSHSession
删除SSH会话命令:
Remove-SSHSession -Index 0 -Verbose
执行SSH命令:
Invoke-SSHCommand -Index 0 -Command“uname -a”
添加SFTP会话命令:
New-SFTPSession -ComputerName 192.168.190.148 -Credential(Get-Credential root)
获取SFTP会话命令:
GET-SFTPSession
获取当前目录命令:
Get-SFTPCurrentDirectory -Index 0
切换到其他目录命令:
Set-SFTPDirectoryPath -Index 0 -Path / usr / bin
也可以一起写到脚本执行,比如我执行uname -a和df -k两个命令
$username = "root" $password = "123456" $secure = $password | ConvertTo-SecureString -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($username,$secure) New-SSHSession -ComputerName 192.168.190.148 -Credential $cred -AcceptKey Invoke-SSHCommand -SessionId 0 -Command "uname -a" Invoke-SSHCommand -SessionId 0 -Command "df -k"
执行脚本 注意替换脚本里的主机地址、账号、密码。
B)SSHSessions
Install-module -Name SSHSessions 安装SSHSessions
get-command -Module sshsessions 查看命令
建立一个新的ssh会话 New-SshSession -ComputerName 192.168.190.148 -Username root -Password 123456 Enter-SshSession -ComputerName 192.168.190.148 进入交互模式
也可以使用invoke-sshcommand的模式实现命令 Invoke-SshCommand -ComputerName 192.168.190.148 -Command "ifconfig"
大家还可以安装一下其他的ssh模块,实现在Powershell中的ssh功能。
0x03 删除SSH模块
例如删除posh-ssh模块
remove-module -name posh-ssh -Force -Verbose -Debug
同样还需要删除模块的目录
C:\Program Files\WindowsPowerShell\Modules 目录下为powershell安装的模块目录
删除即可
其他删除模块的方法也是一样的。
相关文章
- ssh安装和出现的问题
- Web 版 SSH Gateone
- SecureCRT ,专业的ssh终端工具
- Linux 温习(三): 远程连接(SSH)
- Mac 生成 SSH 密钥
- Linux无密码SSH安全连接的极致体验(linux无密码ssh)
- Linux实现免密码SSH登录方法(linux免密码ssh登陆)
- 服务Linux开启SSH服务轻松实现远程登录(linux开机启动ssh)
- 密钥Linux下查看SSH密钥的快捷方式(查看Linux的ssh)
- 让Linux轻松破解SSH密钥(linux破解ssh)
- Debian 安装 fail2ban 方式SSH爆破攻击
- Linux SSH:失去连接的困扰(linuxssh掉线)
- 服务器重启Linux服务器:通过SSH连接来实现(ssh重启linux)
- 使用Linux SSH跳板机提升服务器安全性(linuxssh跳板机)
- Linux下远程操作之SSH命令(linux命令ssh)
- 运行健壮:使用Linux的SSH服务器(linux的ssh服务器)
- SSH工具——Linux下必备的远程连接神器(ssh工具linux)
- SSH配置MySQL: 实现远程访问MySQL数据库的方法(ssh配置mysql)
- Putty是一个免费的telnet、rlogin和ssh客户端,但是功能丝毫不逊色于商业的telnet类工具。
- Linux下安全SSH连接实现公钥认证(linux ssh 公钥)
- Linux 系统快速安装SSH服务指南(linux 安装ssh)
- 快速掌握SSH连接Linux实现服务器远程操作(ssh 连接 linux)
- 重启Redis,从SSH远程控制(ssh重启redis)
- SSH远程配置Redis实现服务器性能优化(ssh 配置 redis)
- 使用SSH安全连接到Redis服务器(ssh连接到redis)
- 使用Redis连接SSH隧道实现安全存储(redis连接ssh隧道)