This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
BlackCap's profile picture

ssh and dns - access any computer remotely

Started by BlackCap, 06 April 2015 - 05:33 PM
BlackCap #1
Posted 06 April 2015 - 07:33 PM
I found that implementing a new protocol for each new program, on each new computer in my network was way too much work, so I decided to implement ssh, which is basically remote access to a computer as if you where sitting in front of it.
In my implementation I felt that remembering IDs was a tedious task, so I made a quick dns implementation too.

dns is not required for ssh to work, but handy for organizing lots of computers.

Files:
Spoilerdns_server: pastebin get Fr66zLSn server
dns_client: pastebin get ZuDbvKXA dns

ssh_server: pastebin get GKUdv2Dt server
ssh_exit: pastebin get Lbu2cVtu exit
ssh_client: pastebin get FnBb0vFE ssh

open: pastebin get bqDQPkGx open
close: pastebin get 77hUjE85 close

Setup:
SpoilerYou need at least 2 computers of any type with rednet access - 3 if you want dns.

The dns server will automatically connect to the rednet, and will assume that a [wireless] modem is placed on the top. It also requires a file named db, containing "{}" without the quotes.

The ssh server will not connect to the rednet automatically, and whenever a session is closed it will reboot. In order to close a ssh session the server will need the ssh_exit file. Because the ssh server reboots when a session is closed, it is recommended that you create a startup file containing something along the lines of.

rednet.open("top")
shell.run("server")

In order to lookup the ssh server on the dns server, you will also need the dns_client file, and should run:

dns register livingroom
if you want the computer to be named "livingroom". Note that the computer have to be connected to the rednet to run this command successfully.

The client will at least need the ssh_client file, and the dns_client file too if you want to use the dns server.

The "open" and "close" files are utility programs that you can use to open/close a rednet connection, which is useful for a pocket computer. To open rednet on a pocket computer you can use:

open back

Usage:
SpoilerBoth the ssh server and the dns server should be running (ignore the latter if you don't use dns). If you use dns, you can run "ssh" (on the ssh client) to get a list of all registered ssh servers with their id's and hostnames.
To connect to a ssh server, simply type ssh <id>, where id is the number next to the hostname from the previous command. You can also get this number by running the "id" program on the ssh server computer. If done successfully, you should be greeted by this prompt:

> ssh 3
SSH by BlackCap
ssh>
note that you now have a "ssh" prompt rather than a normal prompt, indicating that you are now connected to another machine. You may now use any program on the computer, as if you where sitting in front of it:

>open back
>ssh
3 - server
> id
This is computer #9
> ssh 3
SSH by BlackCap
ssh> id
This is computer #3
This computer is labelled "server"
ssh>
to disconnect from the server, run the exit program on the server:

ssh> exit
Session closed
>
if you simply terminate the program the server will continue to believe that you are connected, and you will be unable to reconnect.

Note that you do not need the dns server in order to access the ssh server, but you will not be able to get the hosname list with the "ssh" command.

This is my first computercraft project and also my first post on this forum, so please bear with me. Any feedback, bug reports and requests are greatly appreciated, and I will continue to support this thing for at least a few months. :)/>
Edited on 06 April 2015 - 08:20 PM
Creator #2
Posted 06 April 2015 - 09:23 PM
Does this communicate trough rednet, or through another sofisticated protocol?
BlackCap #3
Posted 06 April 2015 - 09:53 PM
Does this communicate trough rednet, or through another sofisticated protocol?

Pardon me if I've misinterpreted your question, but it sends my custom made protocol trough rednet
Lyqyd #4
Posted 06 April 2015 - 10:09 PM
Ah, nice! Your ssh program looks like it works in a similar manner to nsh. Do you have plans to add support for the mouse events as well?
BlackCap #5
Posted 06 April 2015 - 10:22 PM
Ah, nice! Your ssh program looks like it works in a similar manner to nsh. Do you have plans to add support for the mouse events as well?

Mouse clicks didn't even occur to me - I implemented them and updated the ssh server and client code in the original post.
I'll have a look at nsh, thanks for the heads up :)/>
Creator #6
Posted 07 April 2015 - 10:55 AM
Does this communicate trough rednet, or through another sofisticated protocol?

Pardon me if I've misinterpreted your question, but it sends my custom made protocol trough rednet

What I meant was if it used rednet, the repeters provided by rednet or a network infrastructure invented by you?