-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ssh2 not working #11947
Comments
|
on mac x86 13.5.2 (Ventura) the error was similar when trying launch an ssh2 server
on linux x86 ubuntu server
|
import { readFileSync } from 'fs';
import { Server, type AuthContext } from 'ssh2';
import net from 'net';
/**
* SSH server's initial configurations.
*/
type ServerConfigurations<T extends AuthContext> = {
/**
* Path to the host key file.
*/
hostKeyPath: string | undefined;
/**
* Authenticates an SSH connection.
*/
authenticate: (context: T) => Promise<boolean>;
/**
* Retrieves an assigned port for local forwarding.
*/
assignPort: (context: T) => Promise<number>;
};
/**
* Creates an SSH server that supports local port forwarding with authentication.
*/
function createServer<T extends AuthContext>({
hostKeyPath,
authenticate,
assignPort,
}: ServerConfigurations<T>) {
const hostKeys = [] as string[];
if (hostKeyPath) {
hostKeys.push(Buffer.from(readFileSync(hostKeyPath)).toString());
}
return new Server(
{
hostKeys,
},
(client) => {
client
.on('authentication', async (ctx) => {
if (!(await authenticate(ctx as T))) {
return ctx.reject();
}
(client as any).assignedPort = await assignPort(ctx as T);
return ctx.accept();
})
.on('ready', () => {
client.on('request', (accept, reject, name, info) => {
if (name === 'tcpip-forward') {
const assignedPort = (client as any)
.assignedPort as number;
if (assignedPort === info.bindPort) {
const server = net
.createServer((socket) => {
socket.setEncoding('utf8');
client.forwardOut(
info.bindAddr,
info.bindPort,
String(socket.remoteAddress),
Number(socket.remotePort),
(err, upstream) => {
if (err) {
console.log(err);
socket.end();
return;
}
upstream
.pipe(socket)
.pipe(upstream);
},
);
})
.listen(info.bindPort);
(client as any).server = server;
return accept && accept();
}
}
return reject && reject();
});
client.on('close', () => {
((client as any).server as net.Server)?.close();
});
});
},
);
}
/**
* SSH functionalities.
*/
export default {
createServer,
}; These scripts work well in my
|
I think this is effectively a duplicate of issue#158, see comment here #158 (comment) I was able to work around this by installing dependencies with optional dependencies omitted, which then omits
|
Duplicate of #4290 |
What version of Bun is running?
1.1.13+bd6a60512
What platform is your computer?
Darwin 23.5.0 arm64 arm
What steps can reproduce the bug?
You can use this code:
What is the expected behavior?
I would expect it to connect and run commands. It works with node without any issues.
What do you see instead?
With bun it just exists with this error:
Additional information
Nope, love bun keep up the great work!
The text was updated successfully, but these errors were encountered: