kstafford3 / ssh2-shell-server Goto Github PK
View Code? Open in Web Editor NEWA wrapper for ssh2 with an eye toward interactive shells.
License: MIT License
A wrapper for ssh2 with an eye toward interactive shells.
License: MIT License
LK"I
Hi There,
Tried to use the passowrd example , but no luck with PuTTY.
Error Report:
Listening on port 5151...
Error! { err: { Error: No supported authentication methods available
at onDISCONNECT (C:\projects_node\ssh_test\ssh_test\ssh_test\node_modules\ssh2-streams\lib\ssh.js:2202:15)
at SSH2Stream. (C:\projects_node\ssh_test\ssh_test\ssh_test\node_modules\ssh2-streams\lib\ssh.js:203:5)
at emitMany (events.js:146:13)
at SSH2Stream.emit (events.js:223:7)
at parsePacket (C:\projects_node\ssh_test\ssh_test\ssh_test\node_modules\ssh2-streams\lib\ssh.js:3748:10)
at SSH2Stream._transform (C:\projects_node\ssh_test\ssh_test\ssh_test\node_modules\ssh2-streams\lib\ssh.js:669:13)
at SSH2Stream.Transform._read (_stream_transform.js:186:10)
at SSH2Stream._read (C:\projects_node\ssh_test\ssh_test\ssh_test\node_modules\ssh2-streams\lib\ssh.js:251:15)
at SSH2Stream.Transform._write (_stream_transform.js:174:12)
at doWrite (_stream_writable.js:387:12) code: 14 },
client:
Client {
domain: null,
_events:
{ ready: [Array],
authentication: [Function],
end: [Function],
error: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
_sshstream:
SSH2Stream {
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_eventsCount: 15,
_maxListeners: undefined,
_writableState: [Object],
writable: true,
allowHalfOpen: true,
_transformState: [Object],
_needContinue: false,
bytesReceived: 256,
bytesSent: 112,
debug: [Function: DEBUG_NOOP],
server: true,
maxPacketSize: 35000,
remoteBugs: 1,
config: [Object],
_state: [Object] },
_channels: {},
_curChan: -1,
_sock:
Socket {
connecting: false,
_hadError: false,
_handle: [Object],
_parent: null,
_host: null,
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_eventsCount: 7,
_maxListeners: undefined,
_writableState: [Object],
writable: true,
allowHalfOpen: false,
_bytesDispatched: 1281,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: [Object],
_server: [Object],
read: [Function],
_consuming: true,
_peername: [Object],
[Symbol(asyncId)]: 8,
[Symbol(bytesRead)]: 0 },
noMoreSessions: false,
authenticated: false },
session: null }
Session Ended
Code:
const { ShellServer, Authenticators } = require('../lib/index');
const fs = require('fs');
const readline = require('readline');
const keyFile = fs.readFileSync('./test_keys/test_key');
const PORT = 5151;
const QUIT_KEYWORDS = [ 'quit', 'exit', 'q' ];
const server = new ShellServer({
hostKeys: [ keyFile ],
port: PORT,
},
Authenticators.authenticateByPassword(checkPassword));
// Authenticators.authenticateByPassword(checkPassword)); // Alternative authentication
server.on('session-created', (session) => {
console.log('Session Created');
session.on('stream-initialized', (stream) => {
console.log('Stream Initialized');
stream.write('Welcome to the password-protected server!\r\n');
const rl = readline.createInterface({
input: stream,
output: stream,
prompt: '>',
});
rl.prompt();
rl.on('line', (line) => {
console.log(`${session.username}: ${line}`);
stream.write(`${line}\r\n`);
if (QUIT_KEYWORDS.indexOf(line.toLowerCase()) > -1) {
rl.close();
}
rl.prompt();
});
rl.on('close', () => {
stream.write('Ok, well, I guess I\'ll talk to you later, then.\r\n');
stream.close();
});
});
});
server.on('session-ended', (e) => {
console.log('Session Ended');
});
server.on('error', (e) => {
console.error('Error!', e);
});
server.listen().then(() => {
console.log(`Listening on port ${PORT}...`);
});
function checkPassword(username, password) {
return password === 'password'; // secure af
}
Hi!
When I use Ctrl+C to exit connection in Are you sure you want to continue connecting (yes/no/[fingerprint])?
, Client will throw an exception. it maybe client object has no listen on 'error', because this code client.removeListener('error', onClientPreHeaderError);
in server.js file.
update:sorry, not in this repo.
LK"I
Hi ,
Thankyou for you excellent SSH2 server library!
Is it possible to use your library to redirect application stdin/stdout to ssh server session?
(for instance redirect the Bash shell to remotely control the PC. )
https://superuser.com/questions/1259194/redirect-process-stdin-and-stdout-to-ssh
Harel
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.