Reputation: 501
I would like to ask how to make a ssh in perl cgi
Not only I want a ssh connection, but also I want to keep this connection. Simply speaking, can I make a web view ssh console?
Pls ignore the secure issue Thanks
Upvotes: 0
Views: 459
Reputation: 2089
I've had more success using Net::SSH2 for SSH connections, but you have to install libssh2 yourself.
For the web server, your best bet would be a simple Plack app that creates and maintains an SSH connection for the user. When they create a connection, give it an ID (possibly using Data::UUID) and use that as the URL (redirect them to their URL). Then simply accept commands as POST data requests to that URL (using text/plain, not form data). Using UUIDs for URLs would allow one user to have multiple connections easily. The UUID would be impossible to guess, making session hijacking difficult. The user still has to have credentials to make the SSH connection (you should accept the credentials and use them to create the Net::SSH2 object), so there should be very little security risk.
Upvotes: 1
Reputation: 41
hm.... interesting project....
+ For frontend:
completely agree regarding AJAX.... moreover, you can use jquery instead (http://api.jquery.com/jQuery.ajax/)... it will make your life much more easier.
+ For backend:
a simplest idea... call ssh command on each command run on beb iface "ssh host 'command'" ...a simple ssh wrapper will be needed and passphraseless public/private keys also for calling commands on remote machine without password (if you need)...
also you can use Net::SSH instead of ssh command... this will add a little complexity...
more complex idea... you can write a small daemon which will keep and handle ssh connections... using FIFOs you can interact from your CGI script with the daemon in order to setup/drop connections, send/receive commands via ssh...
Hope this helps,
/A
Upvotes: 1