# Running commands over ssh

**URL:** https://discourse.julialang.org/t/running-commands-over-ssh/27103
**Category:** General Usage
**Created:** [August 2, 2019, 7:55am UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103 "2019-08-02T07:55:03Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [August 2, 2019, 7:55am UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/1 "2019-08-02T07:55:03Z")

</div>

I would like to run commands from julia over ssh. I know how to do this in an ad hoc way:

```julia
Cmd(`ssh user@remote 'ls'`)

```

However I wonder is there a way to use the full power of julia command running over ssh?  
That is I would like to do something like this:

```julia
cmd = ssh("user@remote",
    pipeline(Cmd(`ls`, dir="/some/path"), `wc -l`, stdout="SomeRemoteFile.txt")
)
run(cmd)

```

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [August 2, 2019, 3:51pm UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/2 "2019-08-02T15:51:40Z")

</div>

Not exactly what you’re asking about, but if you’re up for using an IDE, there’s awesome functionality built into Juno. [See here](http://docs.junolab.org/latest/man/faq/#Connecting-to-a-Julia-session-on-a-remote-machine-1).

I don’t know the answer to your specific question :-/

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [August 2, 2019, 4:20pm UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/3 "2019-08-02T16:20:42Z")

</div>

If you have the same version of Julia installed on the remote machine (and in the same location), you could use the Distributed library to do this — just `r = addprocs(["remote.server"])` and then `@spawnat r[1] run(...)`.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [August 2, 2019, 5:46pm UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/4 "2019-08-02T17:46:40Z")

</div>

Thanks for the answers so far. I would prefer if julia is not needed at the remote machine or at least not a specific version of julia.

---

<div class="post-metadata">

### Author: ![baumgold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baumgold/32/28576_2.png) [@baumgold](https://discourse.julialang.org/u/baumgold)
#### Post date: [April 11, 2022, 6:13pm UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/5 "2022-04-11T18:13:30Z")

</div>

@jw3126 - Did you ever find a clean solution to running remote commands over ssh from within Julia (without a Julia dependency for the remote server)? Thanks.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [April 11, 2022, 6:53pm UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/6 "2022-04-11T18:53:49Z")

</div>

No I did not.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [April 11, 2022, 7:14pm UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/7 "2022-04-11T19:14:36Z")

</div>

Wouldn’t it be easiest to run an actual shell on the remote with e.g.

```julia
run(`ssh user@remote "/bin/bash -c 'ls /some/path | wc -l > file.txt'"`)

```

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [April 12, 2022, 5:51am UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/8 "2022-04-12T05:51:23Z")

</div>

That might be the best option. It does however not allow to use julia abstractions like `pipeline` over ssh, right?

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [April 12, 2022, 7:35am UTC](https://discourse.julialang.org/t/running-commands-over-ssh/27103/9 "2022-04-12T07:35:15Z")

</div>

No, but those Julia abstractions are a subset of the functionality provided by most shells, so you could conceivably write a package that creates the proper `Cmd` from your Julia function calls.
