1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# Yo SSH Host Initiator (Y.O.S.H.I)
Yoshi is a lua library that wraps the `ssh` client, allowing you to define complex host configurations using the power of a full programming langage (lua) instead of the `ssh_config` dsl.
Obligatory code example (`~/bin/yossh`):
```lua
#!/usr/bin/env lua
yoshi = require'yoshi'
local function isHome()
local _, _, code = os.execute("nc -z -w1 192.168.50.2 2222")
return code == 0
end
yoshi.hosts["ganymede"] = function()
if isHome() then
return yoshi.ssh{
HostName = "192.168.50.2",
Port = 2222,
LocalForward = 8010
}
else
return yoshi.ssh{
HostName = "williamsfam.us.com",
LocalForward = 8010,
DynamicFoward = 9090
}
end
end
yoshi.hosts["io"] = function()
if isHome() then
return yoshi.ssh{HostName = "192.168.50.3"}
else
return yoshi.ssh{
HostName = "192.168.50.3",
User = "admin",
ProxyJump = "collin@ganymede",
}
end
end
yoshi.run(arg)
```
```
$ yossh io
Connection to 192.168.50.2 2222 port [tcp/ethernet-ip-1] succeeded!
+ ssh admin@192.168.50.3
io:~$
```
## 🍄 Getting Started
First, clone this repo, and make sure you have ssh and lua installed.
```
sudo apt install ssh luajit5.4 # or whatever
git clone https://github.com/bluedragon1221/yoshi
```
Next, place `yoshi.lua` in a place that lua can find it.
Consult the [lua documentation](https://www.lua.org/pil/8.1.html) for help.
Now you can write a simple configuration.
As an example, let's look at the equivelant of this `ssh_config` block:
```
Host box
HostName 192.168.50.3
User yoshi
```
Using Yoshi, it would look like this:
```lua
-- yoshi_cfg.lua
yoshi = require'yoshi'
yoshi.hosts["box"] = yoshi.ssh{
HostName = "192.168.50.3",
User = "yoshi"
}
yoshi.run(arg)
```
> (To create more complicated configurations, read the [docs](./doc/lua_doc.md))
To test your Yoshi configuration, you can run `lua yoshi_cfg.lua`.
This would be annoying to type every time you need to access your remote server, though!
So we'll place the script in the `$PATH` (ex. `~/bin/yossh` or something), and use a shabang to tell the script to execute with lua:
```lua
#!/usr/bin/env lua
yoshi = require'yoshi'
yoshi.hosts["box"] = yoshi.ssh{
HostName = "192.168.50.3",
User = "yoshi"
}
yoshi.run(arg)
```
Assuming `~/bin` is in the `$PATH` and you made `yossh` executable with `chmod +x`, running `yossh` in the terminal will give you a nice help page:
```bash
$ yossh
yossh - smart SSH wrapper
USAGE:
yossh <host>
yossh <user@host>
yossh <host:port>
yossh <user@host:port>
AVAILABLE HOSTS:
- box
```
And you can ssh into `box`:
```bash
$ yossh box
+ ssh yoshi@192.168.50.3
io:~$ whoami
yoshi
```
## 📖 Docs
- [`doc/lua_doc.md`](doc/lua_doc.md) contains comprehensive docs for the Yoshi lua api
- [`doc/nix.md`](doc/nix.md) discusses packaging your Yoshi configuration with nix
---
[](https://brainmade.org)
|