Skip to content

unixshells/dartssh2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dartssh2

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.

Changes from upstream

  • SSH agent forwarding ([email protected])
  • agentForwarding parameter on shell() and execute()
  • onAgentChannel callback for server-initiated agent channels

Features

  • 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.

Quick start

Connect to a remote host

final client = SSHClient(
  await SSHSocket.connect('localhost', 22),
  username: 'user',
  onPasswordRequest: () => 'password',
);

Spawn a shell

final shell = await client.shell();
stdout.addStream(shell.stdout);
stderr.addStream(shell.stderr);
stdin.cast<Uint8List>().listen(shell.write);
await shell.done;
client.close();

Shell with agent forwarding

final shell = await client.shell(agentForwarding: true);

Execute a command

final uptime = await client.run('uptime');
print(utf8.decode(uptime));

Authenticate with public keys

final client = SSHClient(
  socket,
  username: 'user',
  identities: [
    ...SSHKeyPair.fromPem(await File('path/to/id_rsa').readAsString())
  ],
);

Connect through a jump server

final jumpServer = SSHClient(
  await SSHSocket.connect('<jump server>', 22),
  username: '...',
  onPasswordRequest: () => '...',
);

final client = SSHClient(
  await jumpServer.forwardLocal('<target server>', 22),
  username: '...',
  onPasswordRequest: () => '...',
);

SFTP

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());

Supported algorithms

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

License

Copyright (c) 2022 xuty, (c) 2026 Unix Shells. MIT license. See LICENSE.

About

Fork of TerminalStudio/dartssh2 with SSH agent forwarding support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages