Compare commits
2
Commits
00f5b2e001
..
v0.1.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
431dcc3997 | ||
|
|
3224a9c699 |
Generated
+1
-1
@@ -436,7 +436,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,31 @@
|
|||||||
# Dosh
|
# Dosh
|
||||||
|
|
||||||
Dosh is an encrypted remote terminal for fast reconnecting shells. It is meant
|
Dosh is an encrypted remote terminal for fast reconnecting shells.
|
||||||
to replace Mosh and day-to-day interactive SSH sessions.
|
|
||||||
|
|
||||||
It runs a `dosh-server` on the remote machine and a `dosh` client locally. The
|
It runs a `dosh-server` on a Unix-like host and a `dosh` client on macOS,
|
||||||
first setup can use SSH. After that, Dosh can attach over encrypted UDP with
|
Linux, or Windows. Setup can use SSH, then Dosh connects over encrypted UDP,
|
||||||
cached credentials, keep terminal sessions alive, reconnect after network
|
keeps sessions alive across disconnects, supports terminal apps, and can carry
|
||||||
changes, and forward TCP ports.
|
TCP forwarding, file copy, and VS Code Remote-SSH streams.
|
||||||
It also includes native encrypted file copy over the Dosh stream layer.
|
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
- Client: macOS, Linux, Windows
|
- Client: macOS, Linux, Windows
|
||||||
- Server: Unix-like systems with PTYs
|
- Server: Linux and other Unix-like systems with PTYs
|
||||||
|
- Default UDP port: `50000`
|
||||||
- Windows: client only
|
- Windows: client only
|
||||||
- UDP port: one configured server port, default `50000`
|
|
||||||
|
|
||||||
Dosh does not implement SFTP, X11 forwarding, or a Windows server. Windows is
|
Dosh is meant to replace Mosh and everyday interactive SSH sessions. It does
|
||||||
client-only.
|
not currently include SFTP, X11 forwarding, or a Windows server.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Server and client on Unix/macOS:
|
Unix/macOS server and client:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -fsSL https://git.palav.dev/Palav/dosh/raw/branch/main/install.sh | sh -s -- both --repo https://git.palav.dev/Palav/dosh.git --port 50000
|
curl -fsSL https://git.palav.dev/Palav/dosh/raw/branch/main/install.sh | sh -s -- both --repo https://git.palav.dev/Palav/dosh.git --port 50000
|
||||||
```
|
```
|
||||||
|
|
||||||
Client only on Unix/macOS:
|
Unix/macOS client only:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -fsSL https://git.palav.dev/Palav/dosh/raw/branch/main/install.sh | sh -s -- client --repo https://git.palav.dev/Palav/dosh.git
|
curl -fsSL https://git.palav.dev/Palav/dosh/raw/branch/main/install.sh | sh -s -- client --repo https://git.palav.dev/Palav/dosh.git
|
||||||
@@ -39,123 +37,48 @@ Windows client:
|
|||||||
irm https://git.palav.dev/Palav/dosh/raw/branch/main/install.ps1 | iex
|
irm https://git.palav.dev/Palav/dosh/raw/branch/main/install.ps1 | iex
|
||||||
```
|
```
|
||||||
|
|
||||||
## Commands
|
## Use
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dosh setup HOST # import SSH config and trust the Dosh host key
|
dosh setup HOST
|
||||||
dosh HOST # connect
|
dosh HOST
|
||||||
dosh HOST COMMAND # connect and run a command
|
dosh HOST COMMAND
|
||||||
dosh exec HOST COMMAND # run a non-interactive remote command
|
dosh update
|
||||||
dosh cp SRC DST # copy files; use host:path for a remote side
|
|
||||||
dosh ls host:path # list a remote path
|
|
||||||
dosh cat host:path # print a remote file
|
|
||||||
dosh mkdir host:path # create a remote directory
|
|
||||||
dosh rm [-r] host:path # remove a remote file or directory
|
|
||||||
dosh update # update Dosh
|
|
||||||
dosh status HOST # show remote tmux sessions and Dosh service status
|
|
||||||
dosh restart HOST # restart dosh-server and show service status
|
|
||||||
dosh doctor HOST # check config and connectivity
|
|
||||||
dosh recover HOST # clear cached attach state and re-check
|
|
||||||
dosh proxy-stdio HOST 127.0.0.1 22
|
|
||||||
dosh vscode HOST [PATH] # configure/open VS Code Remote-SSH through Dosh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Examples:
|
Useful commands:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dosh server
|
dosh exec HOST COMMAND
|
||||||
dosh server tm
|
dosh cp SRC DST
|
||||||
dosh exec server 'uname -a'
|
dosh ls host:path
|
||||||
dosh cp file.txt server:tmp/file.txt
|
dosh cat host:path
|
||||||
dosh cp -r server:Projects/app ./app
|
dosh mkdir host:path
|
||||||
dosh cp -r server:Projects/app backup:app
|
dosh rm [-r] host:path
|
||||||
dosh ls server:Projects
|
dosh forward HOST -L 8080:127.0.0.1:80
|
||||||
dosh cat server:tmp/file.txt
|
dosh forward HOST -D 1080
|
||||||
dosh forward server -L 8080:127.0.0.1:80
|
dosh forward HOST -R 2222:127.0.0.1:22
|
||||||
dosh forward server -D 1080
|
dosh status HOST
|
||||||
dosh forward server -R 2222:127.0.0.1:22
|
dosh doctor HOST
|
||||||
dosh proxy-stdio server 127.0.0.1 22
|
dosh recover HOST
|
||||||
dosh vscode server /home/me/project
|
dosh restart HOST
|
||||||
```
|
```
|
||||||
|
|
||||||
Agent forwarding is opt-in with `-A` and must be enabled on the server.
|
Agent forwarding is opt-in with `-A` and must also be enabled on the server.
|
||||||
File copy is enabled by `allow_file_transfer = true` on the server.
|
File copy must be enabled by the server config.
|
||||||
|
|
||||||
## VS Code
|
## VS Code
|
||||||
|
|
||||||
Dosh can carry VS Code Remote-SSH without replacing VS Code's SSH workflow.
|
Dosh can carry VS Code Remote-SSH through its transport:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dosh vscode setup server
|
dosh vscode setup HOST
|
||||||
dosh vscode server /home/me/project
|
dosh vscode HOST /remote/path
|
||||||
```
|
```
|
||||||
|
|
||||||
This writes a managed SSH config entry using:
|
This creates a managed SSH config entry using `ProxyCommand dosh proxy-stdio`.
|
||||||
|
VS Code still uses Remote-SSH and its normal remote server; Dosh carries the
|
||||||
```sshconfig
|
SSH byte stream.
|
||||||
ProxyCommand dosh proxy-stdio server %h %p
|
|
||||||
```
|
|
||||||
|
|
||||||
VS Code still uses Remote-SSH and the normal remote VS Code Server. Dosh carries
|
|
||||||
the SSH byte stream over its encrypted reconnecting transport.
|
|
||||||
|
|
||||||
The optional extension in `vscode-extension/` provides the same setup from the
|
|
||||||
Command Palette.
|
|
||||||
|
|
||||||
## Library
|
|
||||||
|
|
||||||
Dosh can also be used as a Rust transport for application protocols that need
|
|
||||||
encrypted streams, roaming, reconnect behavior, keepalives, retransmission,
|
|
||||||
flow control, and in-order delivery.
|
|
||||||
|
|
||||||
Use `dosh::client::DoshClient` and `dosh::server::DoshServer` for the complete
|
|
||||||
native-auth path. Use `dosh::transport::DoshTransport` or `StreamMux` only when
|
|
||||||
you already have your own session/auth layer.
|
|
||||||
|
|
||||||
Client-side SDK:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
let client = dosh::client::DoshClient::load()?;
|
|
||||||
let mut dosh = client
|
|
||||||
.connect("server")
|
|
||||||
.service("myapp")
|
|
||||||
.connect()
|
|
||||||
.await?
|
|
||||||
.into_transport();
|
|
||||||
|
|
||||||
let stream = dosh.open_service("myapp").await?;
|
|
||||||
dosh.send(stream, b"hello").await?;
|
|
||||||
```
|
|
||||||
|
|
||||||
Server-side SDK:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
let config = dosh::server::DoshServerConfig::default()
|
|
||||||
.service("myapp")?;
|
|
||||||
let mut server = dosh::server::DoshServer::bind(config).await?;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
match server.recv().await? {
|
|
||||||
dosh::server::DoshServerEvent::Accepted(client) => {
|
|
||||||
eprintln!("accepted {:?}", client.conn_id);
|
|
||||||
}
|
|
||||||
dosh::server::DoshServerEvent::Session { conn_id, event } => {
|
|
||||||
if let dosh::transport::SessionEvent::Stream(
|
|
||||||
dosh::transport::TransportEvent::Open(open)
|
|
||||||
) = event {
|
|
||||||
server.accept_stream(conn_id, open.stream_id).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dosh::server::DoshServerEvent::Ignored => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The server runtime owns UDP reads and demuxes packets by connection id, so
|
|
||||||
multiple clients can share one Dosh port without per-session readers racing.
|
|
||||||
|
|
||||||
Runnable SDK examples live in `examples/sdk_echo_server.rs` and
|
|
||||||
`examples/sdk_echo_client.rs`.
|
|
||||||
|
|
||||||
## Config
|
## Config
|
||||||
|
|
||||||
@@ -169,8 +92,21 @@ Common client settings:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
default_session = "new"
|
default_session = "new"
|
||||||
auth_preference = "native,ssh"
|
|
||||||
predict = true
|
predict = true
|
||||||
cache_attach_tickets = true
|
cache_attach_tickets = true
|
||||||
disconnect_status = true
|
disconnect_status = true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Rust Library
|
||||||
|
|
||||||
|
Dosh exposes a Rust transport for encrypted, reconnecting application streams.
|
||||||
|
Use `dosh::client::DoshClient` and `dosh::server::DoshServer` for the normal
|
||||||
|
native-auth path. Use `dosh::transport::DoshTransport` only when you already
|
||||||
|
own session setup and authentication.
|
||||||
|
|
||||||
|
Runnable examples:
|
||||||
|
|
||||||
|
```text
|
||||||
|
examples/sdk_echo_client.rs
|
||||||
|
examples/sdk_echo_server.rs
|
||||||
|
```
|
||||||
|
|||||||
+42
-10
@@ -1491,6 +1491,7 @@ async fn proxy_stdio_loop(mut transport: DoshTransport, stream_id: u64) -> Resul
|
|||||||
for chunk in data.chunks {
|
for chunk in data.chunks {
|
||||||
stdout.write_all(&chunk).await?;
|
stdout.write_all(&chunk).await?;
|
||||||
}
|
}
|
||||||
|
stdout.flush().await?;
|
||||||
}
|
}
|
||||||
SessionEvent::Stream(TransportEvent::Close { stream_id: closed }) if closed == stream_id => {
|
SessionEvent::Stream(TransportEvent::Close { stream_id: closed }) if closed == stream_id => {
|
||||||
stdout.flush().await?;
|
stdout.flush().await?;
|
||||||
@@ -1529,22 +1530,29 @@ fn run_vscode_command(config: &dosh::config::ClientConfig, args: &Args) -> Resul
|
|||||||
if tokens.next().is_some() {
|
if tokens.next().is_some() {
|
||||||
return Err(anyhow!("dosh vscode accepts at most one remote path"));
|
return Err(anyhow!("dosh vscode accepts at most one remote path"));
|
||||||
}
|
}
|
||||||
let alias = ensure_vscode_ssh_host(config, args, host)?;
|
let generated = ensure_vscode_ssh_host(config, args, host)?;
|
||||||
println!("[ok] VS Code SSH host: {alias}");
|
println!("[ok] VS Code SSH host: {}", generated.alias);
|
||||||
println!("[ok] Dosh proxy: dosh proxy-stdio {host} 127.0.0.1 22");
|
println!("[ok] SSH target: 127.0.0.1:{}", generated.target_ssh_port);
|
||||||
|
println!("[ok] Dosh proxy: {}", generated.proxy_command);
|
||||||
if launch {
|
if launch {
|
||||||
launch_vscode_remote(&alias, remote_path)?;
|
launch_vscode_remote(&generated.alias, remote_path)?;
|
||||||
} else {
|
} else {
|
||||||
println!("Open in VS Code Remote-SSH as: {alias}");
|
println!("Open in VS Code Remote-SSH as: {}", generated.alias);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct GeneratedVscodeHost {
|
||||||
|
alias: String,
|
||||||
|
proxy_command: String,
|
||||||
|
target_ssh_port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
fn ensure_vscode_ssh_host(
|
fn ensure_vscode_ssh_host(
|
||||||
config: &dosh::config::ClientConfig,
|
config: &dosh::config::ClientConfig,
|
||||||
args: &Args,
|
args: &Args,
|
||||||
requested: &str,
|
requested: &str,
|
||||||
) -> Result<String> {
|
) -> Result<GeneratedVscodeHost> {
|
||||||
let hosts = load_hosts_config(None).unwrap_or_default();
|
let hosts = load_hosts_config(None).unwrap_or_default();
|
||||||
let host_config = hosts.hosts.get(requested).cloned().unwrap_or_default();
|
let host_config = hosts.hosts.get(requested).cloned().unwrap_or_default();
|
||||||
let raw_server = host_config
|
let raw_server = host_config
|
||||||
@@ -1554,6 +1562,7 @@ fn ensure_vscode_ssh_host(
|
|||||||
let server = ssh_with_user(&raw_server, host_config.user.as_deref());
|
let server = ssh_with_user(&raw_server, host_config.user.as_deref());
|
||||||
let ssh_port = args.ssh_port.or(host_config.ssh_port).or(config.ssh_port);
|
let ssh_port = args.ssh_port.or(host_config.ssh_port).or(config.ssh_port);
|
||||||
let ssh_config = ssh_config(&server, ssh_port).unwrap_or_default();
|
let ssh_config = ssh_config(&server, ssh_port).unwrap_or_default();
|
||||||
|
let target_ssh_port = ssh_config.port.or(ssh_port).unwrap_or(22);
|
||||||
let user = host_config
|
let user = host_config
|
||||||
.user
|
.user
|
||||||
.or(ssh_username(&server))
|
.or(ssh_username(&server))
|
||||||
@@ -1563,11 +1572,22 @@ fn ensure_vscode_ssh_host(
|
|||||||
.ok()
|
.ok()
|
||||||
.map(|path| path.display().to_string())
|
.map(|path| path.display().to_string())
|
||||||
.unwrap_or_else(|| "dosh".to_string());
|
.unwrap_or_else(|| "dosh".to_string());
|
||||||
let mut proxy_command = shell_word(&exe);
|
let mut proxy_command = ssh_config_word(&exe);
|
||||||
|
if let Some(host) = args
|
||||||
|
.dosh_host
|
||||||
|
.clone()
|
||||||
|
.or_else(|| host_config.dosh_host.clone())
|
||||||
|
.or_else(|| config.dosh_host.clone())
|
||||||
|
{
|
||||||
|
proxy_command.push_str(&format!(" --dosh-host {}", ssh_config_word(&host)));
|
||||||
|
}
|
||||||
if let Some(port) = args.dosh_port.or(host_config.port) {
|
if let Some(port) = args.dosh_port.or(host_config.port) {
|
||||||
proxy_command.push_str(&format!(" --dosh-port {port}"));
|
proxy_command.push_str(&format!(" --dosh-port {port}"));
|
||||||
}
|
}
|
||||||
proxy_command.push_str(&format!(" proxy-stdio {} %h %p", shell_word(requested)));
|
proxy_command.push_str(&format!(
|
||||||
|
" proxy-stdio {} %h %p",
|
||||||
|
ssh_config_word(requested)
|
||||||
|
));
|
||||||
let ssh_dir = expand_tilde("~/.ssh");
|
let ssh_dir = expand_tilde("~/.ssh");
|
||||||
fs::create_dir_all(&ssh_dir).with_context(|| format!("create {}", ssh_dir.display()))?;
|
fs::create_dir_all(&ssh_dir).with_context(|| format!("create {}", ssh_dir.display()))?;
|
||||||
let include_path = ssh_dir.join("config.dosh");
|
let include_path = ssh_dir.join("config.dosh");
|
||||||
@@ -1577,7 +1597,7 @@ fn ensure_vscode_ssh_host(
|
|||||||
block.push_str(&format!("# BEGIN DOSH {alias}\n"));
|
block.push_str(&format!("# BEGIN DOSH {alias}\n"));
|
||||||
block.push_str(&format!("Host {alias}\n"));
|
block.push_str(&format!("Host {alias}\n"));
|
||||||
block.push_str(" HostName 127.0.0.1\n");
|
block.push_str(" HostName 127.0.0.1\n");
|
||||||
block.push_str(" Port 22\n");
|
block.push_str(&format!(" Port {target_ssh_port}\n"));
|
||||||
block.push_str(&format!(" HostKeyAlias {requested}\n"));
|
block.push_str(&format!(" HostKeyAlias {requested}\n"));
|
||||||
if let Some(user) = user {
|
if let Some(user) = user {
|
||||||
block.push_str(&format!(" User {user}\n"));
|
block.push_str(&format!(" User {user}\n"));
|
||||||
@@ -1588,7 +1608,11 @@ fn ensure_vscode_ssh_host(
|
|||||||
block.push_str(&format!(" ProxyCommand {proxy_command}\n"));
|
block.push_str(&format!(" ProxyCommand {proxy_command}\n"));
|
||||||
block.push_str(&format!("# END DOSH {alias}\n"));
|
block.push_str(&format!("# END DOSH {alias}\n"));
|
||||||
upsert_managed_block(&include_path, &alias, &block)?;
|
upsert_managed_block(&include_path, &alias, &block)?;
|
||||||
Ok(alias)
|
Ok(GeneratedVscodeHost {
|
||||||
|
alias,
|
||||||
|
proxy_command,
|
||||||
|
target_ssh_port,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_ssh_include(path: &Path, include: &str) -> Result<()> {
|
fn ensure_ssh_include(path: &Path, include: &str) -> Result<()> {
|
||||||
@@ -3145,6 +3169,14 @@ fn shell_word(value: &str) -> String {
|
|||||||
format!("'{}'", value.replace('\'', "'\\''"))
|
format!("'{}'", value.replace('\'', "'\\''"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ssh_config_word(value: &str) -> String {
|
||||||
|
if cfg!(windows) {
|
||||||
|
format!("\"{}\"", value.replace('"', "\\\""))
|
||||||
|
} else {
|
||||||
|
shell_word(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn local_bootstrap(
|
fn local_bootstrap(
|
||||||
session: &str,
|
session: &str,
|
||||||
mode: &str,
|
mode: &str,
|
||||||
|
|||||||
Reference in New Issue
Block a user