天道酬勤,学无止境

ssh

如何在 golang CLI 中的远程机器上执行命令?(How do I execute a command on a remote machine in a golang CLI?)

问题 如何在 golang CLI 中的远程机器上执行命令? 我需要编写一个 golang CLI,它可以通过密钥通过 SSH 连接到远程机器并执行 shell 命令。 此外,我需要能够做到这一点。 例如,通过 SSH 连接到一台机器(如云堡垒),然后通过 SSH 连接到另一台内部机器并执行 shell 命令。 我还没有(还)找到任何例子。 回答1 尝试使用 os/exec https://golang.org/pkg/os/exec/ 执行 ssh package main import ( "bytes" "log" "os/exec" ) func main() { cmd := exec.Command("ssh", "remote-machine", "bash-command") var out bytes.Buffer cmd.Stdout = &out err := cmd.Run() if err != nil { log.Fatal(err) } } 要跳过机器,请使用 ssh 配置文件中的 ProxyCommand 指令。 Host remote_machine_name ProxyCommand ssh -q bastion nc remote_machine_ip 22 回答2 您可以使用"golang.org/x/crypto/ssh"包通过 SSH

2021-06-24 10:54:12    分类:技术分享    go   ssh   command-line-interface

bash: does expect work with multiple password prompts?

I am currently using expect to pass in passwords so my scripts can run automatically without me having to sit around and type in the same password over and over again. Important: Please don't comment about how big of a security risk this is or how I should be using ssh keys, I would use those if I could, but the setup I have to work with doesn't allow it. My code looks like the following: #!/bin/sh PASS=mypassword /usr/bin/expect -c " spawn python Tools/python/install.py expect -nocase \"password:\" {send \"$PASS\r\"; interact} " The problem I have is that install.py prompts for the same

2021-06-24 10:49:27    分类:问答    bash   ssh   passwords   expect

ssh agent forwarding inside cron jobs

I wonder why ssh agent forwarding does not work in cron jobs. I have a simple script such as: ssh -A remote_host "ls ~" I can run this script without any password typing, but after putting it inside a cron job, it always failed with: Permission denied, please try again. Received disconnect from ip_of_remote_host: 2: Too many authentication failures for myuser Can anyone please tell me how to fix this issue? Thanks a lot!

2021-06-24 10:41:41    分类:问答    linux   ssh

How to use environment modules in a ssh command line?

The Environment Modules package is used for dynamic modification of a user's environment (debian package environment-modules). I would like to use module directly from a ssh command line. The purpose is to be able to execute commands on different nodes from a bash script executed on a front node. I don't want to explicitly update PATH and LD_LIBRARY_PATH environment variables for each different node configuration. When I directly connect to the node and then call module from the node, it is obviously working: jyvet> ssh mynode jyvet@mynode> module load gcc-6.0 jyvet@mynode> gcc --version gcc

2021-06-24 10:06:01    分类:问答    bash   shell   ssh   environment-variables   environment-modules

setting up github ssh on windows 7 machine

I just installed git on my windows machine using git's how to guide, but I am having a problem. When I run ssh -T git@github.com step I am getting this error: ssh_exchange_identification: read: Connection reset by peer here is a longer trace that I got by running ssh -vvv git@github.com: OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 debug2: ssh_connect: needpriv 0 debug1: Connecting to github.com [207.97.227.239] port 22. debug1: Connection established. debug1: identity file /c/Users/bmehanni/.ssh/identity type -1 debug3: Not a RSA1 key file /c/Users/bmehanni/.ssh/id_rsa. debug2: key_type_from

2021-06-24 07:52:31    分类:问答    git   ssh   github

Unable to add ssh-key of EC2 instance to bitbucket account

I want to clone a repository to an EC2 instance I'm using. I generated ssh key pair using "ssh-keygen". Your public key has been saved in /home/ubuntu/.ssh/id_rsa2.pub. the id_rsa2.pub looks something like: ssh-rsa a_very_long_sequence ubuntu@ip-a-b-c-d I pasted the key as it is to the keys associated with my bit bucket account. But I'm being prompted Invalid SSH key (ssh-keygen).

2021-06-24 07:29:17    分类:问答    git   ssh   amazon-ec2   rsa   bitbucket

本地主机中的 Ansible SSH 错误连接(Ansible SSH ERROR connection in localhost)

问题 当我针对本地主机启动我的剧本时出现此错误。 TASK [setup] ******************************************************************* fatal: [127.0.0.1]: UNREACHABLE! => {"changed": false, "msg": "SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true} to retry, use: --limit @deploy-test-env.retry PLAY RECAP ********************************************************************* 127.0.0.1 : ok=0 changed=0 unreachable=1 failed=0 我的主机文件有这个配置: [local] 127.0.0.1 问题是什么? 谢谢! 回答1 Ansible 默认尝试通过

2021-06-24 06:52:05    分类:技术分享    ssh   ansible   ansible-playbook

Git push over SSH on Windows won't work

I've got an enigma for you guys! After an half a day struggle on this issue, I require your experience to enlighten me on git usage on Windows with msysgit. The context: Windows 8 msysgit, last version Using SSH Key authentication Pagent handles SSH key authentication using valid .ppk key (logon with PuTTY is OK) The bare repository is healthy, with permissions OK. Working with git linux client (tested on local Ubuntu VM with the same SSH key) Env: GIT_SSH=D:\path\to\PuTTY\plink.exe HOME=C:\path\to\myself The issue: Short: error: insufficient permission for adding an object to repository

2021-06-24 06:41:35    分类:问答    windows   git   ssh   msysgit

Heroku 键“无法读取未定义的属性‘运行’”(Heroku keys “Cannot read property 'run' of undefined”)

问题 我正在尝试使用 Heroku cli“密钥”功能将 ssh 密钥上传到我的帐户。 不幸的是,每当我尝试使用任何键方法时,都会遇到以下错误。 TypeError: Cannot read property 'run' of undefined at Object.<anonymous> (C:\Users\Administrator\AppData\Local\heroku\tmp\heroku-script-292666295:14:4) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:456:32) at tryModuleLoad (module.js:415:12) at Function.Module._load (module.js:407:3) at Function.Module.runMain (module.js:575:10) at startup (node.js:159:18) at node.js:444:3 任何想法将不胜感激。 回答1 在与 Heroku 支持团队交谈后,我们发现heroku update解决了这个问题。 回答2 看来,Heroku

2021-06-24 05:54:17    分类:技术分享    node.js   heroku   ssh

Xcode - Authentication failed error when adding repository with SSH auth

I am trying to add repository via Xcode > Settings > Accounts and I am stuck on the proper address. Address of our repo is quite simple: my.domain.com:port/project-name. Authentication via SSH Keys. Could someone help me to understand what's going on here? See screenshot below. By the way running git clone git+ssh://git@my.domain.com:port/project-name works fine. EDIT Running git clone without git+ssh// git clone git@my.domain.cz:2222/project-name or git clone git@my.domain.cz:22/project-name is giving me same error: ssh: connect to host my.domain.cz port 22: Connection refused fatal: Could

2021-06-24 05:32:25    分类:问答    xcode   git   ssh   xcode7