[英]remotely login to linux using powershell
I am using the following script (ssh module)to remotely login to a linux server to start a process. 我正在使用以下脚本(ssh模块)远程登录linux服务器以启动进程。 This 'prompts' me for the credentials at the command line.
这“提示”我在命令行中输入凭据。 I am trying to run this script through Bamboo So, is there a way I can pass the credentials while I run the script like, so that it wont prompt me for credentials while running the script?
我正在尝试通过Bamboo运行此脚本。那么,有没有办法像我一样运行脚本时传递凭据,以免在运行脚本时提示我输入凭据?
PS C:\SVN_Working> .\linux-maint.ps1 -UserName user1 -Password pass123
$agents=("cagent01")
function Start-LinuxAgents([array]$agents){
if ($agents.length -gt 0){
$agents | %{
New-SshSession -ComputerName $_
$ExecStart = Invoke-SshCommand -InvokeOnAll -Quiet -Command './start'
Remove-SshSession -ComputerName $_
}
}
}
SSH has the ability to authenticate users via a password, or via a public/private keypair. SSH能够通过密码或公共/专用密钥对对用户进行身份验证。
You could create a private key with no password, add the public key to ~/.ssh/authorized_keys on the Linux server, and then specify your private key when creating a session via New-SshSession in the script. 您可以创建不带密码的私钥,将公钥添加到Linux服务器上的〜/ .ssh / authorized_keys中,然后在脚本中通过New-SshSession创建会话时指定私钥。
See http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library#New-SshSession 参见http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library#New-SshSession
and on generating a public/private SSH key: https://help.github.com/articles/generating-ssh-keys/ 并生成公共/私有SSH密钥: https : //help.github.com/articles/generating-ssh-keys/
*note: If you create an SSH key without a password, it means that anyone who has possession of that private key can access any system with the matching public key. *注:如果创建不带密码的SSH密钥,则意味着拥有该私钥的任何人都可以使用匹配的公钥访问任何系统。 This is a security risk - you may want to look into restricting the commands the user is allowed to run on the remote system (also part of SSH's functionality)
这存在安全风险-您可能需要研究限制用户在远程系统上运行的命令的限制(这也是SSH功能的一部分)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.