SSH example not working "dial unix: missing address"

3,027 views
Skip to first unread message

Sam Fourman Jr.

unread,
Jun 19, 2014, 5:09:14 AM6/19/14
to golan...@googlegroups.com
I am new to golang, and I am trying to run a command remotely via ssh.

I have found a example, but I am confused as to why it wont work, it compiles fine
but I always get this runtime error and I don't understand why?

dial unix: missing address


I think it has to do with the following code,

agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
if err != nil {
log.Fatal(err)
}




here is the full example:


Thank you for any insight.
--

Sam Fourman Jr.

Brian Stengaard

unread,
Jun 19, 2014, 9:06:10 AM6/19/14
to golan...@googlegroups.com
Works just fine here.

It would seem you haven't exported the SSH_AUTH_SOCK environment variable. Most likely since you are not runnig an ssh agent.

root@0863af494d85:/# env
| grep AUTH_SOCK
root@0863af494d85:/# eval $(ssh-agent)
Agent pid 3110
root@0863af494d85:/# env | grep AUTH_SOCK
SSH_AUTH_SOCK=/tmp/ssh-mcGXzz6Gxmwq/agent.3109
root@0863af494d85:/# ssh-add /root/.ssh/id_rsa
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

Don't forget to add an SSH key to your agent (otherwise your example will just fail a little later).

/Brian

bga...@golang.org

unread,
Jun 19, 2014, 9:08:47 AM6/19/14
to golan...@googlegroups.com
That error message is printed when you don't pass an address to Dial.
Can you confirm that you've set SSH_AUTH_SOCK appropriately?

Nidhish Gautam

unread,
Jul 15, 2021, 1:42:10 PM7/15/21
to golang-nuts
eval 'ssh-agent'
[output]
SSH_AUTH_SOCK=/tmp/ssh-Ond9LaZuIebk/agent.18010; export SSH_AUTH_SOCK;
SSH_AGENT_PID=18011; export SSH_AGENT_PID;
echo Agent pid 18011;

copy and paste the output in terminal again. Its like setting env varaibles.

then run:
ssh-add ~/.ssh/id_rsa

make sure your both rsa keys are there in ~/.ssh/ folder
Reply all
Reply to author
Forward
0 new messages