Fork of TerminalStudio/dartssh2 with SSH agent forwarding support. Maintained by Unix Shells.
SSH and SFTP client written in pure Dart. Works with Dart VM and Flutter.
- SSH agent forwarding (
[email protected]) agentForwardingparameter onshell()andexecute()onAgentChannelcallback for server-initiated agent channels
- Pure Dart: Works with both Dart VM and Flutter.
- SSH Session: Execute commands, spawn shells, set environment variables, pseudo terminals.
- Authentication: Password, public key (Ed25519, RSA, ECDSA), keyboard-interactive.
- Agent forwarding: Forward SSH agent to remote hosts.
- Port forwarding: Local and remote forwarding.
- Jump host: Connect through a jump server (ProxyJump).
- SFTP: Upload, download, list, link, remove, rename, statvfs.
final client = SSHClient(
await SSHSocket.connect('localhost', 22),
username: 'user',
onPasswordRequest: () => 'password',
);final shell = await client.shell();
stdout.addStream(shell.stdout);
stderr.addStream(shell.stderr);
stdin.cast<Uint8List>().listen(shell.write);
await shell.done;
client.close();final shell = await client.shell(agentForwarding: true);final uptime = await client.run('uptime');
print(utf8.decode(uptime));final client = SSHClient(
socket,
username: 'user',
identities: [
...SSHKeyPair.fromPem(await File('path/to/id_rsa').readAsString())
],
);final jumpServer = SSHClient(
await SSHSocket.connect('<jump server>', 22),
username: '...',
onPasswordRequest: () => '...',
);
final client = SSHClient(
await jumpServer.forwardLocal('<target server>', 22),
username: '...',
onPasswordRequest: () => '...',
);final sftp = await client.sftp();
// List directory
final items = await sftp.listdir('/');
for (final item in items) {
print(item.longname);
}
// Read file
final file = await sftp.open('/etc/passwd');
final content = await file.readBytes();
// Write file
final file = await sftp.open('file.txt', mode: SftpFileOpenMode.write);
await file.writeBytes(utf8.encode('hello') as Uint8List);
// Upload
final file = await sftp.open('file.txt',
mode: SftpFileOpenMode.create | SftpFileOpenMode.write);
await file.write(File('local_file.txt').openRead().cast());| Type | Algorithms |
|---|---|
| Host key | ssh-ed25519, ecdsa-sha2-nistp{256,384,521}, rsa-sha2-{256,512}, ssh-rsa |
| Key exchange | curve25519-sha256, ecdh-sha2-nistp{256,384,521}, diffie-hellman-group-exchange-sha{1,256}, diffie-hellman-group14-sha{1,256} |
| Cipher | aes{128,192,256}-ctr, aes{128,192,256}-cbc |
| MAC | hmac-sha2-{256,512}, hmac-sha2-{256,512}[email protected], hmac-sha1, hmac-md5 |
Copyright (c) 2022 xuty, (c) 2026 Unix Shells. MIT license. See LICENSE.