setup-ssh-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- setup_ssh/__init__.py +3 -0
- setup_ssh/__main__.py +3 -0
- setup_ssh/cli.py +216 -0
- setup_ssh/fleet.py +228 -0
- setup_ssh/render.py +106 -0
- setup_ssh/state.py +159 -0
- setup_ssh/templates/posix.sh +110 -0
- setup_ssh/templates/windows.ps1 +184 -0
- setup_ssh/transport.py +427 -0
- setup_ssh_cli-0.1.0.dist-info/METADATA +115 -0
- setup_ssh_cli-0.1.0.dist-info/RECORD +15 -0
- setup_ssh_cli-0.1.0.dist-info/WHEEL +5 -0
- setup_ssh_cli-0.1.0.dist-info/entry_points.txt +2 -0
- setup_ssh_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- setup_ssh_cli-0.1.0.dist-info/top_level.txt +1 -0
setup_ssh/transport.py
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"""Local execution and SSH sessions with explicit, pinned host-key trust."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
import getpass
|
|
7
|
+
import hashlib
|
|
8
|
+
import os
|
|
9
|
+
import platform
|
|
10
|
+
import shutil
|
|
11
|
+
import socket
|
|
12
|
+
import subprocess
|
|
13
|
+
import time
|
|
14
|
+
from collections.abc import Callable
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import paramiko
|
|
19
|
+
from cryptography.exceptions import UnsupportedAlgorithm
|
|
20
|
+
|
|
21
|
+
from .state import Device, Inventory, SetupError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DeviceUnavailableError(SetupError):
|
|
25
|
+
"""The device's SSH port could not be reached."""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def fingerprint(key: paramiko.PKey) -> str:
|
|
29
|
+
digest = hashlib.sha256(key.asbytes()).digest()
|
|
30
|
+
return "SHA256:" + base64.b64encode(digest).decode().rstrip("=")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def local_platform() -> str:
|
|
34
|
+
name = platform.system()
|
|
35
|
+
try:
|
|
36
|
+
return {"Windows": "windows", "Darwin": "macos", "Linux": "linux"}[name]
|
|
37
|
+
except KeyError as exc:
|
|
38
|
+
raise SetupError(f"Unsupported operating system: {name}.") from exc
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def current_account_matches(user: str) -> bool:
|
|
42
|
+
current = getpass.getuser()
|
|
43
|
+
if local_platform() != "windows":
|
|
44
|
+
return user == current
|
|
45
|
+
names = {current.casefold()}
|
|
46
|
+
if os.environ.get("USERDOMAIN"):
|
|
47
|
+
names.add(f"{os.environ['USERDOMAIN']}\\{current}".casefold())
|
|
48
|
+
if os.environ.get("USERDNSDOMAIN"):
|
|
49
|
+
names.add(f"{current}@{os.environ['USERDNSDOMAIN']}".casefold())
|
|
50
|
+
return user.casefold() in names
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def verify_local_address(device: Device) -> None:
|
|
54
|
+
"""Avoid applying a copied inventory's local entry on the wrong computer."""
|
|
55
|
+
for family, kind, protocol, _, address in socket.getaddrinfo(
|
|
56
|
+
device.host, 0, type=socket.SOCK_STREAM
|
|
57
|
+
):
|
|
58
|
+
try:
|
|
59
|
+
with socket.socket(family, kind, protocol) as sock:
|
|
60
|
+
sock.bind(address)
|
|
61
|
+
return
|
|
62
|
+
except OSError:
|
|
63
|
+
continue
|
|
64
|
+
raise SetupError(
|
|
65
|
+
f"{device.name}: {device.host} does not belong to this computer. "
|
|
66
|
+
"Use its current LAN/NetBird address, or enroll it without --local."
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass
|
|
71
|
+
class Result:
|
|
72
|
+
code: int
|
|
73
|
+
stdout: str = ""
|
|
74
|
+
stderr: str = ""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class Session:
|
|
78
|
+
def __init__(self, device: Device, transport: paramiko.Transport | None = None):
|
|
79
|
+
self.device = device
|
|
80
|
+
self.transport = transport
|
|
81
|
+
|
|
82
|
+
def close(self) -> None:
|
|
83
|
+
if self.transport is not None:
|
|
84
|
+
self.transport.close()
|
|
85
|
+
|
|
86
|
+
def command(self, command: str | list[str], data: str = "", timeout: int = 60) -> Result:
|
|
87
|
+
if self.transport is None:
|
|
88
|
+
if isinstance(command, str):
|
|
89
|
+
raise ValueError("Local commands must be an argument list.")
|
|
90
|
+
try:
|
|
91
|
+
process = subprocess.run(
|
|
92
|
+
command, input=data, capture_output=True, text=True, timeout=timeout
|
|
93
|
+
)
|
|
94
|
+
except FileNotFoundError as exc:
|
|
95
|
+
raise SetupError(f"Missing {command[0]}. Run setup-ssh doctor.") from exc
|
|
96
|
+
except subprocess.TimeoutExpired as exc:
|
|
97
|
+
raise SetupError(
|
|
98
|
+
f"{self.device.name}: command timed out after {timeout}s."
|
|
99
|
+
) from exc
|
|
100
|
+
return Result(process.returncode, process.stdout, process.stderr)
|
|
101
|
+
if not isinstance(command, str):
|
|
102
|
+
raise ValueError("Remote commands must be strings.")
|
|
103
|
+
channel = self.transport.open_session(timeout=timeout)
|
|
104
|
+
channel.settimeout(timeout)
|
|
105
|
+
try:
|
|
106
|
+
channel.exec_command(command)
|
|
107
|
+
if data:
|
|
108
|
+
channel.sendall(data.encode("utf-8"))
|
|
109
|
+
channel.shutdown_write()
|
|
110
|
+
stdout = bytearray()
|
|
111
|
+
stderr = bytearray()
|
|
112
|
+
deadline = time.monotonic() + timeout
|
|
113
|
+
while True:
|
|
114
|
+
while channel.recv_ready():
|
|
115
|
+
stdout.extend(channel.recv(65536))
|
|
116
|
+
while channel.recv_stderr_ready():
|
|
117
|
+
stderr.extend(channel.recv_stderr(65536))
|
|
118
|
+
if channel.exit_status_ready() and not (
|
|
119
|
+
channel.recv_ready() or channel.recv_stderr_ready()
|
|
120
|
+
):
|
|
121
|
+
break
|
|
122
|
+
if time.monotonic() > deadline:
|
|
123
|
+
raise SetupError(f"{self.device.name}: command timed out after {timeout}s.")
|
|
124
|
+
time.sleep(0.01)
|
|
125
|
+
return Result(
|
|
126
|
+
channel.recv_exit_status(),
|
|
127
|
+
stdout.decode("utf-8-sig", errors="replace"),
|
|
128
|
+
stderr.decode("utf-8-sig", errors="replace"),
|
|
129
|
+
)
|
|
130
|
+
finally:
|
|
131
|
+
channel.close()
|
|
132
|
+
|
|
133
|
+
def run(self, script: str, timeout: int = 60) -> Result:
|
|
134
|
+
if self.device.platform == "windows":
|
|
135
|
+
# The fixed loader keeps cmd.exe's 8191-character command limit out of the way.
|
|
136
|
+
loader = (
|
|
137
|
+
"[Console]::InputEncoding = New-Object Text.UTF8Encoding($false); "
|
|
138
|
+
"[Console]::OutputEncoding = New-Object Text.UTF8Encoding($false); "
|
|
139
|
+
"$payload = [Console]::In.ReadLine(); "
|
|
140
|
+
"& ([ScriptBlock]::Create([Text.Encoding]::UTF8.GetString("
|
|
141
|
+
"[Convert]::FromBase64String($payload))))"
|
|
142
|
+
)
|
|
143
|
+
encoded = base64.b64encode(loader.encode("utf-16le")).decode()
|
|
144
|
+
args = [
|
|
145
|
+
"powershell.exe",
|
|
146
|
+
"-NoLogo",
|
|
147
|
+
"-NoProfile",
|
|
148
|
+
"-NonInteractive",
|
|
149
|
+
"-ExecutionPolicy",
|
|
150
|
+
"Bypass",
|
|
151
|
+
"-EncodedCommand",
|
|
152
|
+
encoded,
|
|
153
|
+
]
|
|
154
|
+
command = subprocess.list2cmdline(args) if self.transport else args
|
|
155
|
+
# Windows OpenSSH may keep stdin open after SSH EOF. A framed line
|
|
156
|
+
# completes without EOF, even for scripts beyond cmd.exe's size limit.
|
|
157
|
+
data = base64.b64encode(script.encode("utf-8")).decode() + "\n"
|
|
158
|
+
else:
|
|
159
|
+
command = "sh -s" if self.transport else ["sh", "-s"]
|
|
160
|
+
data = script
|
|
161
|
+
return self.command(command, data, timeout)
|
|
162
|
+
|
|
163
|
+
def detect_platform(self) -> None:
|
|
164
|
+
if self.transport is None:
|
|
165
|
+
actual = local_platform()
|
|
166
|
+
if self.device.platform not in {"auto", actual}:
|
|
167
|
+
raise SetupError(f"This computer runs {actual}, not {self.device.platform}.")
|
|
168
|
+
self.device.platform = actual
|
|
169
|
+
return
|
|
170
|
+
if self.device.platform != "auto":
|
|
171
|
+
return
|
|
172
|
+
result = self.command("uname -s", timeout=15)
|
|
173
|
+
name = result.stdout.strip()
|
|
174
|
+
if result.code == 0 and name in {"Linux", "Darwin"}:
|
|
175
|
+
self.device.platform = {"Linux": "linux", "Darwin": "macos"}[name]
|
|
176
|
+
return
|
|
177
|
+
result = self.command(
|
|
178
|
+
"powershell.exe -NoLogo -NoProfile -NonInteractive -Command "
|
|
179
|
+
'"[Environment]::OSVersion.Platform.ToString()"',
|
|
180
|
+
timeout=15,
|
|
181
|
+
)
|
|
182
|
+
if result.code == 0 and "Win32NT" in result.stdout:
|
|
183
|
+
self.device.platform = "windows"
|
|
184
|
+
return
|
|
185
|
+
raise SetupError(
|
|
186
|
+
f"Cannot detect {self.device.name}'s OS. Set --os linux, macos, or windows."
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class Connector:
|
|
191
|
+
def __init__(
|
|
192
|
+
self,
|
|
193
|
+
inventory: Inventory,
|
|
194
|
+
*,
|
|
195
|
+
timeout: int = 10,
|
|
196
|
+
batch: bool = False,
|
|
197
|
+
confirm: Callable[[str], bool],
|
|
198
|
+
save: Callable[[], None],
|
|
199
|
+
password: Callable[[str], str] = getpass.getpass,
|
|
200
|
+
):
|
|
201
|
+
self.inventory = inventory
|
|
202
|
+
self.timeout = timeout
|
|
203
|
+
self.batch = batch
|
|
204
|
+
self.confirm = confirm
|
|
205
|
+
self.save = save
|
|
206
|
+
self.password = password
|
|
207
|
+
|
|
208
|
+
def verify(self, device: Device, key: paramiko.PKey) -> None:
|
|
209
|
+
offered = {"type": key.get_name(), "data": key.get_base64()}
|
|
210
|
+
if device.host_key is not None:
|
|
211
|
+
if device.host_key != offered:
|
|
212
|
+
raise SetupError(
|
|
213
|
+
f"{device.name}: SSH host key CHANGED ({fingerprint(key)}). "
|
|
214
|
+
"Check the device identity before updating its inventory pin."
|
|
215
|
+
)
|
|
216
|
+
return
|
|
217
|
+
known = paramiko.HostKeys()
|
|
218
|
+
path = Path.home() / ".ssh" / "known_hosts"
|
|
219
|
+
if path.is_file():
|
|
220
|
+
try:
|
|
221
|
+
known.load(str(path))
|
|
222
|
+
except (OSError, paramiko.SSHException, ValueError) as exc:
|
|
223
|
+
raise SetupError(f"Cannot read {path}: {exc}") from exc
|
|
224
|
+
host = device.host if device.port == 22 else f"[{device.host}]:{device.port}"
|
|
225
|
+
existing = known.lookup(host)
|
|
226
|
+
trusted = existing is not None and key.get_name() in existing
|
|
227
|
+
if trusted and existing[key.get_name()] != key:
|
|
228
|
+
raise SetupError(
|
|
229
|
+
f"{device.name}: host key conflicts with {path}. Check the device identity."
|
|
230
|
+
)
|
|
231
|
+
if not trusted:
|
|
232
|
+
if self.batch:
|
|
233
|
+
raise SetupError(f"{device.name}: unknown host key. Run sync interactively first.")
|
|
234
|
+
if not self.confirm(
|
|
235
|
+
f"{device.name} ({device.host}:{device.port})\n"
|
|
236
|
+
f" {key.get_name()} {fingerprint(key)}\n"
|
|
237
|
+
"Compare this fingerprint with the device's host key. Trust this device?"
|
|
238
|
+
):
|
|
239
|
+
raise SetupError(f"{device.name}: host key was not trusted.")
|
|
240
|
+
device.host_key = offered
|
|
241
|
+
self.save()
|
|
242
|
+
|
|
243
|
+
def handshake(self, device: Device) -> paramiko.Transport:
|
|
244
|
+
try:
|
|
245
|
+
sock = socket.create_connection((device.host, device.port), timeout=self.timeout)
|
|
246
|
+
except OSError as exc:
|
|
247
|
+
raise DeviceUnavailableError(
|
|
248
|
+
f"{device.name} ({device.host}:{device.port}): {exc}. "
|
|
249
|
+
"Check SSH server, address, firewall, and NetBird TCP access policy. "
|
|
250
|
+
"Run setup-ssh doctor for setup instructions."
|
|
251
|
+
) from exc
|
|
252
|
+
transport = paramiko.Transport(sock)
|
|
253
|
+
transport.banner_timeout = self.timeout
|
|
254
|
+
transport.auth_timeout = self.timeout
|
|
255
|
+
# Keep a stored host key's algorithm stable even if SSH defaults change.
|
|
256
|
+
if device.host_key:
|
|
257
|
+
key_type = device.host_key["type"]
|
|
258
|
+
options = transport.get_security_options()
|
|
259
|
+
allowed = tuple(
|
|
260
|
+
name
|
|
261
|
+
for name in options.key_types
|
|
262
|
+
if name == key_type or (key_type == "ssh-rsa" and name.startswith("rsa-sha2-"))
|
|
263
|
+
)
|
|
264
|
+
if allowed:
|
|
265
|
+
options.key_types = allowed
|
|
266
|
+
try:
|
|
267
|
+
transport.start_client(timeout=self.timeout)
|
|
268
|
+
if not transport.is_active():
|
|
269
|
+
raise SetupError(f"{device.name}: SSH handshake did not complete.")
|
|
270
|
+
self.verify(device, transport.get_remote_server_key())
|
|
271
|
+
transport.set_keepalive(30)
|
|
272
|
+
return transport
|
|
273
|
+
except BaseException:
|
|
274
|
+
transport.close()
|
|
275
|
+
raise
|
|
276
|
+
|
|
277
|
+
def key_candidates(self):
|
|
278
|
+
seen: set[bytes] = set()
|
|
279
|
+
# Also works while revoking this computer after removing its local-device entry.
|
|
280
|
+
paths = [Path.home() / ".ssh" / "setup-ssh" / self.inventory.group_id / "id_ed25519"]
|
|
281
|
+
for path in paths:
|
|
282
|
+
if path.is_file():
|
|
283
|
+
try:
|
|
284
|
+
key = paramiko.PKey.from_path(path)
|
|
285
|
+
seen.add(key.asbytes())
|
|
286
|
+
yield key
|
|
287
|
+
except (
|
|
288
|
+
OSError,
|
|
289
|
+
ValueError,
|
|
290
|
+
TypeError,
|
|
291
|
+
UnsupportedAlgorithm,
|
|
292
|
+
paramiko.SSHException,
|
|
293
|
+
paramiko.pkey.UnknownKeyType,
|
|
294
|
+
):
|
|
295
|
+
pass
|
|
296
|
+
agent = paramiko.Agent()
|
|
297
|
+
try:
|
|
298
|
+
for key in agent.get_keys():
|
|
299
|
+
if key.asbytes() not in seen:
|
|
300
|
+
seen.add(key.asbytes())
|
|
301
|
+
yield key
|
|
302
|
+
finally:
|
|
303
|
+
agent.close()
|
|
304
|
+
for name in ("id_ed25519", "id_ecdsa", "id_rsa"):
|
|
305
|
+
path = Path.home() / ".ssh" / name
|
|
306
|
+
if not path.is_file():
|
|
307
|
+
continue
|
|
308
|
+
try:
|
|
309
|
+
key = paramiko.PKey.from_path(path)
|
|
310
|
+
if key.asbytes() not in seen:
|
|
311
|
+
seen.add(key.asbytes())
|
|
312
|
+
yield key
|
|
313
|
+
except (
|
|
314
|
+
OSError,
|
|
315
|
+
ValueError,
|
|
316
|
+
TypeError,
|
|
317
|
+
UnsupportedAlgorithm,
|
|
318
|
+
paramiko.SSHException,
|
|
319
|
+
paramiko.pkey.UnknownKeyType,
|
|
320
|
+
):
|
|
321
|
+
continue
|
|
322
|
+
|
|
323
|
+
def open(self, device: Device) -> Session:
|
|
324
|
+
transport = None
|
|
325
|
+
try:
|
|
326
|
+
if device.local:
|
|
327
|
+
if not current_account_matches(device.user):
|
|
328
|
+
raise SetupError(
|
|
329
|
+
f"Local device user is {device.user}; run this inventory as that account."
|
|
330
|
+
)
|
|
331
|
+
verify_local_address(device)
|
|
332
|
+
# Verify the incoming server, but perform local writes as the current account.
|
|
333
|
+
transport = self.handshake(device)
|
|
334
|
+
transport.close()
|
|
335
|
+
transport = None
|
|
336
|
+
session = Session(device)
|
|
337
|
+
else:
|
|
338
|
+
transport = self.handshake(device)
|
|
339
|
+
candidates = self.key_candidates()
|
|
340
|
+
try:
|
|
341
|
+
for key in candidates:
|
|
342
|
+
if not transport.is_active():
|
|
343
|
+
break
|
|
344
|
+
try:
|
|
345
|
+
transport.auth_publickey(device.user, key)
|
|
346
|
+
except (paramiko.AuthenticationException, paramiko.SSHException):
|
|
347
|
+
continue
|
|
348
|
+
if transport.is_authenticated():
|
|
349
|
+
break
|
|
350
|
+
finally:
|
|
351
|
+
candidates.close()
|
|
352
|
+
if not transport.is_authenticated():
|
|
353
|
+
if self.batch:
|
|
354
|
+
raise SetupError(
|
|
355
|
+
f"{device.name}: key login failed; run sync interactively."
|
|
356
|
+
)
|
|
357
|
+
transport.close()
|
|
358
|
+
transport = self.handshake(device)
|
|
359
|
+
secret = self.password(f"Password for {device.user}@{device.host}: ")
|
|
360
|
+
try:
|
|
361
|
+
transport.auth_password(device.user, secret)
|
|
362
|
+
finally:
|
|
363
|
+
del secret
|
|
364
|
+
if not transport.is_authenticated():
|
|
365
|
+
raise SetupError(
|
|
366
|
+
f"{device.name}: authentication requires additional steps."
|
|
367
|
+
)
|
|
368
|
+
session = Session(device, transport)
|
|
369
|
+
session.detect_platform()
|
|
370
|
+
return session
|
|
371
|
+
except SetupError:
|
|
372
|
+
if transport:
|
|
373
|
+
transport.close()
|
|
374
|
+
raise
|
|
375
|
+
except (OSError, paramiko.SSHException, EOFError) as exc:
|
|
376
|
+
if transport:
|
|
377
|
+
transport.close()
|
|
378
|
+
raise SetupError(
|
|
379
|
+
f"{device.name} ({device.host}:{device.port}): {exc}. "
|
|
380
|
+
"Check SSH server, address, firewall, and NetBird TCP access policy. "
|
|
381
|
+
"Run setup-ssh doctor for setup instructions."
|
|
382
|
+
) from exc
|
|
383
|
+
except BaseException:
|
|
384
|
+
if transport:
|
|
385
|
+
transport.close()
|
|
386
|
+
raise
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def doctor_instructions(target: str) -> str:
|
|
390
|
+
if target == "windows":
|
|
391
|
+
return """Windows — run PowerShell as Administrator:
|
|
392
|
+
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
|
|
393
|
+
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
|
|
394
|
+
Start-Service sshd
|
|
395
|
+
Set-Service sshd -StartupType Automatic
|
|
396
|
+
Get-NetFirewallRule -Name OpenSSH-Server-In-TCP
|
|
397
|
+
If that firewall rule is missing, create it for the interface/network you use.
|
|
398
|
+
Use a local or Active Directory account with an account password (not a Windows Hello PIN).
|
|
399
|
+
Default Windows administrator accounts share administrators_authorized_keys."""
|
|
400
|
+
if target == "macos":
|
|
401
|
+
return """macOS:
|
|
402
|
+
System Settings → General → Sharing → Remote Login → On
|
|
403
|
+
Allow access for the account you will use.
|
|
404
|
+
OpenSSH client and ssh-keygen are included with macOS."""
|
|
405
|
+
return """Linux — install the OpenSSH client and server for your distribution:
|
|
406
|
+
Debian/Ubuntu: sudo apt install openssh-client openssh-server
|
|
407
|
+
sudo systemctl enable --now ssh
|
|
408
|
+
Fedora: sudo dnf install openssh-clients openssh-server
|
|
409
|
+
sudo systemctl enable --now sshd
|
|
410
|
+
Allow the chosen SSH port through your host firewall on the network you use.
|
|
411
|
+
Use your regular account; root SSH login may be disabled by server policy."""
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def diagnostics() -> list[str]:
|
|
415
|
+
lines = []
|
|
416
|
+
for name in ("ssh", "ssh-keygen", "netbird"):
|
|
417
|
+
found = shutil.which(name)
|
|
418
|
+
lines.append(f"{name}: {found or 'not installed / not on PATH'}")
|
|
419
|
+
if shutil.which("netbird"):
|
|
420
|
+
try:
|
|
421
|
+
process = subprocess.run(
|
|
422
|
+
["netbird", "status"], capture_output=True, text=True, timeout=10
|
|
423
|
+
)
|
|
424
|
+
lines.append(process.stdout.strip() or process.stderr.strip())
|
|
425
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
426
|
+
lines.append(f"NetBird status unavailable: {exc}")
|
|
427
|
+
return lines
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: setup-ssh-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Set up passwordless SSH between your Linux, Windows, and macOS devices.
|
|
5
|
+
Author: beepboopbit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/BeepBoopBit/setup-ssh
|
|
8
|
+
Project-URL: Issues, https://github.com/BeepBoopBit/setup-ssh/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/BeepBoopBit/setup-ssh#readme
|
|
10
|
+
Keywords: ssh,openssh,passwordless,netbird,cli
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: System :: Systems Administration
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: paramiko<5,>=3.4
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# setup-ssh
|
|
26
|
+
|
|
27
|
+
I made this because my lazy ass got tired of setting up SSH keys and remembering
|
|
28
|
+
IP addresses whenever I wanted to use another computer.
|
|
29
|
+
|
|
30
|
+
It's mostly for my own Linux, Mac, and Windows machines. Add them, sync, and then
|
|
31
|
+
use shortcuts like `ssh mac` or `ssh linux`. It sets up passwordless access in
|
|
32
|
+
both directions between the accounts you add.
|
|
33
|
+
|
|
34
|
+
This project uses **AI-driven development**. I use AI tools to help write the code
|
|
35
|
+
and docs and work through fixes.
|
|
36
|
+
|
|
37
|
+
## Get it running
|
|
38
|
+
|
|
39
|
+
You'll need Python 3.11+ on the computer running setup. The other computers just
|
|
40
|
+
need OpenSSH enabled and a working network connection. LAN is fine; I use NetBird
|
|
41
|
+
too, but you need to set that up separately.
|
|
42
|
+
|
|
43
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/), then get the
|
|
44
|
+
published package from PyPI:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
uv tool install setup-ssh-cli
|
|
48
|
+
setup-ssh init
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This works on Linux, macOS, and Windows. Update later with
|
|
52
|
+
`uv tool upgrade setup-ssh-cli`.
|
|
53
|
+
|
|
54
|
+
Or use `python -m pip install setup-ssh-cli` inside a virtual environment.
|
|
55
|
+
|
|
56
|
+
Working from a clone of this repository? Use `./dev.sh install` instead, or
|
|
57
|
+
`.\dev.ps1 install` on Windows. `setup-ssh init` is the part that sets up your
|
|
58
|
+
devices.
|
|
59
|
+
|
|
60
|
+
Include your current computer in the wizard. It'll ask for each device's name,
|
|
61
|
+
address, username, OS, and SSH port. Keep the devices online for this first setup.
|
|
62
|
+
Verify the host fingerprints when asked; you may need each account's password
|
|
63
|
+
once so setup can install the keys.
|
|
64
|
+
|
|
65
|
+
After a successful sync:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
ssh mac # from Linux
|
|
69
|
+
ssh linux # from the Mac
|
|
70
|
+
scp notes.txt mac:~/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Use whatever names you gave your devices. Each computer keeps its own private
|
|
74
|
+
key, and you don't need to run setup again just to SSH into something.
|
|
75
|
+
|
|
76
|
+
## Add another computer
|
|
77
|
+
|
|
78
|
+
Enable SSH on it, then run these from your original setup computer:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
setup-ssh add --no-sync
|
|
82
|
+
setup-ssh sync --skip-offline
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
That sets up whichever computers are available. Run sync again when the others
|
|
86
|
+
are online so they get the new keys too. If everyone's online, `setup-ssh add`
|
|
87
|
+
does both steps for you.
|
|
88
|
+
|
|
89
|
+
## Commands I use
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
setup-ssh list # saved devices
|
|
93
|
+
setup-ssh sync --skip-offline # update the ones that are online
|
|
94
|
+
setup-ssh --batch sync --skip-offline # same, with no password/trust prompts
|
|
95
|
+
setup-ssh check # test every direction; all devices online
|
|
96
|
+
setup-ssh remove desktop # remove a device's managed access
|
|
97
|
+
setup-ssh doctor --os windows # SSH setup instructions for an OS
|
|
98
|
+
setup-ssh --help
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Removing a device needs to reach the other computers to revoke its access there.
|
|
102
|
+
If some are offline, sync them later.
|
|
103
|
+
|
|
104
|
+
## More details
|
|
105
|
+
|
|
106
|
+
The longer explanations live here:
|
|
107
|
+
|
|
108
|
+
- [Usage guide](https://github.com/BeepBoopBit/setup-ssh/blob/main/docs/usage.md) — all the options, files, backups, and how keys work.
|
|
109
|
+
- [Troubleshooting](https://github.com/BeepBoopBit/setup-ssh/blob/main/docs/troubleshooting.md) — when something inevitably refuses to connect.
|
|
110
|
+
- [Contributing](https://github.com/BeepBoopBit/setup-ssh/blob/main/CONTRIBUTING.md) — running it locally and working on the code.
|
|
111
|
+
- [Dev commands](https://github.com/BeepBoopBit/setup-ssh/blob/main/docs/development.md) — install, update, test, and build.
|
|
112
|
+
- [Publishing](https://github.com/BeepBoopBit/setup-ssh/blob/main/docs/publishing.md) — the PyPI setup and release steps.
|
|
113
|
+
- [Security](https://github.com/BeepBoopBit/setup-ssh/blob/main/SECURITY.md) — the access model and reporting issues.
|
|
114
|
+
|
|
115
|
+
[MIT](https://github.com/BeepBoopBit/setup-ssh/blob/main/LICENSE) · beepboopbit
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
setup_ssh/__init__.py,sha256=mwTZzwsPpqcmV4g4W5MgAAc1-7oh7IW6HygE1oVPsYU,82
|
|
2
|
+
setup_ssh/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
|
|
3
|
+
setup_ssh/cli.py,sha256=m7fonz-6uYOse3m96Qo-RaQFt6lTtEuf-te10Y-d0Co,9579
|
|
4
|
+
setup_ssh/fleet.py,sha256=n1nk5-03jFdVF7NtVluP3VIPCqbOcPYwaGACFBqohx4,9833
|
|
5
|
+
setup_ssh/render.py,sha256=rS5tTa4mO16ye5Sn-ZiK_LSeKpAX7hLgTzBg_1-bkGU,4082
|
|
6
|
+
setup_ssh/state.py,sha256=T2q8AmA22W0fXo4u0xk-bPUTcpbPcIf-cYMcrBh5LL4,6231
|
|
7
|
+
setup_ssh/transport.py,sha256=EsASN0ax6cvxI4_oZz12G1MBrdiOP1nTInGYUAxNiNY,17109
|
|
8
|
+
setup_ssh/templates/posix.sh,sha256=9B9p4aUMAmOwVF7FrFKnjCIhajc27hOlWDrS5-lHLSk,4494
|
|
9
|
+
setup_ssh/templates/windows.ps1,sha256=EYlfVhHmy8vFT7ccpsnZnI6n8YiABr7dPkMahi7fbGs,8521
|
|
10
|
+
setup_ssh_cli-0.1.0.dist-info/licenses/LICENSE,sha256=ufSQzZ_p35UUknKgkk3_KbyBl15LuKgWc32RrK9_71k,1068
|
|
11
|
+
setup_ssh_cli-0.1.0.dist-info/METADATA,sha256=sB6pbb1xEnSeOKlusKkA0A_fb4TQ9MKAz9-q6WyYR5k,4584
|
|
12
|
+
setup_ssh_cli-0.1.0.dist-info/WHEEL,sha256=a-udL2m4V_6Yn8b-uKzWb12RjRxwwMo6ohYFM24tpaY,91
|
|
13
|
+
setup_ssh_cli-0.1.0.dist-info/entry_points.txt,sha256=9lppZSEWwEv7WT5My3fqX4ctHWfs3TFwKIMgucSE4mU,49
|
|
14
|
+
setup_ssh_cli-0.1.0.dist-info/top_level.txt,sha256=QQVqA-jgb6Nk5XQ_OHmqqMc47MLh0p2kFfdmp_3QHBA,10
|
|
15
|
+
setup_ssh_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 beepboopbit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
setup_ssh
|