powershell ssh免密码登录服务器

  1. ssh-keygen -t rsa
  2. scp C:\Users\name.ssh\id_rsa.pub name@ip:~/.ssh/
  3. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys\
  4. notepad++ ./ssh/config
  5. Host name-alias
    User name #远程服务器中你的用户名
    Hostname 10.168.66.1 #远程服务器ip
    IdentityFile C:\Users\name.ssh\id_rsa #本地私钥地址
  6. ssh name-alias
PowerShell中,你可以使用OpenSSH模块来登录SSH服务器。以下是一个示例: 1. 首先,确保你的计算机已安装OpenSSH模块。你可以在PowerShell中运行以下命令来检查: ``` Get-Module -ListAvailable OpenSSH* ``` 如果没有安装OpenSSH模块,你可以使用以下命令来安装它: ``` Install-Module -Name OpenSSH.Client -Force ``` 2. 安装完毕后,你可以使用以下命令来登录SSH服务器: ``` $username = 'your_username' $password = 'your_password' $hostname = 'ssh_server_hostname' $session = New-SSHSession -ComputerName $hostname -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -AsPlainText $password -Force)) ``` 请注意替换`your_username`、`your_password`和`ssh_server_hostname`为相应的值。 3. 成功登录后,你可以执行命令或操作远程服务器。以下是一些示例: - 执行命令并获取输出: ``` Invoke-SSHCommand -SessionId $session.SessionId -Command 'your_command' ``` - 上传文件到SSH服务器: ``` Set-SCPFile -SessionId $session.SessionId -LocalFile 'local_file_path' -RemotePath 'remote_file_path' ``` - 下载文件从SSH服务器: ``` Get-SCPFile -SessionId $session.SessionId -RemotePath 'remote_file_path' -LocalFile 'local_file_path' ``` - 关闭SSH会话: ``` Remove-SSHSession -SessionId $session.SessionId ``` 这是一个基本的示例,你可以根据需要进行调整和扩展。注意,登录SSH服务器需要提供正确的用户名、密码和主机名。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值