using blink shell's ssh for ssh instead of nmsssh idk why it doesnt work

This commit is contained in:
neon443 committed 2025-06-05 12:46:42 +01:00
1 parent 7d206478ea
commit 4e2c47f09a
7 files changed
+249 -5

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
//
// SSHHandler.swift
// ShhShell
//
// Created by neon443 on 05/06/2025.
//
import Foundation
import NMSSH
import LibSSH
class SSHHandler: ObservableObject {
var session: NMSSHSession
var shellHandlerDelegate = ShellHandler()
init(
session: NMSSHSession = NMSSHSession(host: "localhost:32222", andUsername: "neon443")
) {
ssh_new()
self.session = session
session.connectToAgent()
}
func connect() {
session.authenticate(
byPublicKey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIaFx9u3BMq2qW1SJzQik7k8/9p9KV8KZ9JehyKKd2Wu",
privateKey: """
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz
c2gtZWQyNTUxOQAAACCGhcfbtwTKtqltUic0IpO5PP/afSlfCmfSXociindlrgAA
AIgKUk2MClJNjAAAAAtzc2gtZWQyNTUxOQAAACCGhcfbtwTKtqltUic0IpO5PP/a
fSlfCmfSXociindlrgAAAEClrzCbl2ZGxAdqa1rS3w3ZEDKXi7Ysf4FKJO375Lhx
54aFx9u3BMq2qW1SJzQik7k8/9p9KV8KZ9JehyKKd2WuAAAAAAECAwQF
-----END OPENSSH PRIVATE KEY-----
""",
andPassword: nil
)
if session.isConnected {
// session.authenticate(byPassword: "password")
do {
try session.channel.startShell()
} catch {
print(error.localizedDescription)
}
session.channel.delegate = shellHandlerDelegate
}
}
func testExec() {
guard session.isConnected else { return }
session.channel.execute("ls", error: nil)
}
}
+26
View File
@@ -0,0 +1,26 @@
//
// ShellHandler.swift
// ShhShell
//
// Created by neon443 on 05/06/2025.
//
import Foundation
import NMSSH
class ShellHandler: NSObject, NMSSHChannelDelegate {
func channel(_ channel: NMSSHChannel, didReadData message: String) {
print(channel)
print(message)
}
func channel(_ channel: NMSSHChannel, didReadError error: String) {
print(error)
print("error")
}
func channelShellDidClose(_ channel: NMSSHChannel) {
print(channel)
print("closed channel")
}
}
+6 -1
View File
@@ -6,15 +6,20 @@
//
import SwiftUI
import NMSSH
struct ContentView: View {
var sshHandler = SSHHandler()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button("go") {
sshHandler.connect()
sshHandler.testExec()
}
}
.padding()
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.