4
votes

I am trying to use vagrant, Clojure and emacs together. Specifically, I can't connect cider to my vagrant machine.

It works locally, when I run cider-jack-in inside my project. But I don't know what are the steps to do that inside the same project (synced via vagrant shared folders) on the vagrant machine.

Here is my attempt so far :

  • ssh vagrant, then cd my-project-dir, then lein repl
  • in emacs, cider-connect, input [email protected], port 22

I get the following message :

SSH port forwarding failed. check the nrepl-tunnel buffer.

Inside that buffer :

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011 Privileged ports can only be forwarded by root.

Process nrepl-tunnel exited abnormally with code 255

Ho do I run that as root ? Is it really the problem ? Should I use another port ? Do I have to put something specific in my Clojure code to enable that ? The directions given here are a bit unclear to me.

Note : it differs from this question because emacs runs on the host machine, not on the vagrant machine

Edit :

Here are the detailed steps I did, thanks to @Shlomi's answer :

  • Edit .ssh/config by adding the following (edit IP according to you Vagrantfile) :

    Host vagrant HostName 192.168.50.50 Port 22 User vagrant ForwardAgent yes

  • in the host, start my project with lein repl. Pay attention to the port in the message : nREPL server started on port 42018 on host 127.0.0.1 - nrepl://127.0.0.1:42018

  • in emacs, M-x cider-connect, input vagrant, your password and the port noted by the previous lein command.

  • That's it :)

1

1 Answers

2
votes

It seems the port you are using is the ssh port instead of the nrepl port.

The way I usually use emacs for remote access is through tramp:

  1. Add an entry in .ssh/config for your remote host, say vagrant
  2. In emacs, cider-connect, input vagrant
  3. In recent versions of cider, it will automatically find all active nrepl sessions on that host, and show their project name and port, so select the right one, and you should be able to start working.