programmatically setting up a vpn from PHP - ssh

I have a website in one place which needs to transmit information and ssh to a second server. For security the second place doesn't like ssh in, they want vpn. I have seen postings on here for vpn from android, but is there anything for php under linux?
A command line utility would do it. I want to:
scp a file over, ssh a script, get the output back.

Related

How can I open a web browser on a server that I can connect to through ssh?

I'm in a computer science program at my university (Ryerson) and I'm learning perl programming.
The way we're learning is by hosting perl scripts on our university's server and doing stuff with them.
I'm away from the university and the university's server is very strict about which IP's can use the www2 subdomain (which is the subdomain that runs perl scripts). And the IP I'm working from gets me the error:
Forbidden
You don't have permission to access /~w3dixon/cgi-bin/lab4.cgi on this server.
Apache/2.2.22 (Debian) Server at www2.scs.ryerson.ca Port 80
Here's the link, if you want to try to access the script yourself.
So I'm being blocked. Normally I'd contact the sys admin and get them to unblock me, but a working perl script is due tonight. (I also tried using a VPN, it was blocked as well).
My solution was to SSH with terminal on my mac and/or Putty on my PC into Ryerson's server and use the unix command 'lynx' to run my scripts (since they aren't blocking their own IPs).
I was having some success, until I tried to use the perl get method from an html form (I copy pasted a script from https://www.tutorialspoint.com/perl/perl_cgi.htm just to get started, to see if syntactically correct code would work properly with my lynx strategy).
So when I was working on my script using a terminal at the university (with google chrome), my scripts worked fine.
Ryerson (my university), doesn't have a remote access program set up (other than ssh), but is there a way to access my webpage through their servers on a GUI browser installed on my machine?
An SSH tunnel is most likely the most feasible and easiest way to do what you want. Set up the tunnel like this:
ssh -L8080:www2.scs.ryerson.ca:80 username#www2.scs.ryerson.ca
If the www2 server is not the host you SSH to, simply replace the second instance of it in the command with the SSH server.
I use port 8080 here, as that alleviates you from needing root privileges.
Now, on your local workstation, in your browser, browse to:
http://localhost:8080

Transfering file to remote server behind a gate node with key authentication disabled - and compiling

I'm working on a project that requires me to run my code on a remote Unix server, that is not available to connect to directly (you first have to log in to the "gate" node and then to this server).
What's really bad is that they disabled key authentication, so each time I need to ssh into it, I have to type in my password twice. It's really annoying and I wonder what's the best way to transfer my local modifications of source files to this server, compile and run them without having to provide those passwords so many times.
I have no sudo access to any of those servers (neither to this "gate", nor to this target server). Any ideas on how to make the whole process more efficient?
EDIT: Martin Prikryl provided a great answer below, but it's suitable for Windows and I'm on a Mac :) I guess it might be a good thing to have it documented here also for *NIX systems.
You are looking for SSH tunneling.
WinSCP SFTP client supports one-hop SSH tunneling natively.
See the Tunnel page on WinSCP Advanced Site Settings dialog.
I assume that after you transfer the file, you need to open SSH terminal to compile the file.
You may be able to make use of WinSCP Console window for that step.
Alternatively, if you need/want to use a real SSH terminal client, make use of an existing SSH tunnel, created by WinSCP, and connect with PuTTY (or any other SSH client) over it.
In the Local tunnel port of WinSCP Tunnel page, select a fixed port number (instead of the default Autoselect). In PuTTY enter "localhost" to Host Name and the selected port in Port.
(I'm the author of WinSCP)

Is there a way to allow all users to scp from a specific machine to another specific machine without password?

Currently I have a machine setup to send files it generates via a script to a remote server for file storage, where each user has their own folder on the remote server, which they can then SFTP into to get their files.
Currently, when the machine generating the files copies them over, via SCP, it prompts for a password for the user it's sending to.
What I would like to be able to do is enable the machine to send the files to the individual user accounts without prompting for a password. I've read a few ways to do this by creating ssh keys in each user's accounts. However, due to the volume of users, I was wondering if there was a way to enable machine1 to be able to scp files to any user account on the remote file server without prompting for a password each time?
You can set up host-based authentication on the target host to accept connections from the source host. This will work for any kind of SSH access, not just SCP. If you want to limit users to just SCP, there are ways to do that. see this question for example.
Try something like:
sshpass -p scp -o StrictHostKeyChecking=no source dest
I have used it on some linux machine. Don't know if it always work (last day i tried on osX and it refused cause it will break ssh security)
BTW you have to install sshpass

Connecting to Oracle DB only accessible via SSH

Searched quite a bit on this, but I think it's a bit of a unique case. What I'm asking may not be possible.
I'm taking an online DB class that requires logging into an SSH server and using SQLPLUS to execute commands and then copying and pasting the results into a document to be submitted. I find SQLPLUS to be excruciatingly painful to work with in the command line... You can't press up for the last command, and if you happen to be holding shift while pressing backspace you get garbage characters.
Anyway, I was hoping I could attach a GUI to make my life easier, but there are some major restrictions. I've tried logging in with SQL Developer, but the connection is rejected.
The only way I can get to the SQL database to do my assignments is by logging into the school's SSH server and running SQLPLUS from there. It seems that attempted connections to the Oracle DB from any IP other than the school's SSH servers are rejected.
I was hoping to use SSH tunneling to connect to the DB server from my local machine, but the only open port on the school's SSH server is 22.
Do I have any options? I would just love to have some sort of database program with a terminal window on the bottom part of the screen and a GUI on top.
Is SSH tunneling not working, it sounds like it would be perfect. Take a look at this link.
You should be able to do something like (from a terminal on your home system)
oracle_port=XXXX
ssh -f user#school-server.com -L $oracle_port:school-server.com:$oracle_port -N
Now fire up SQLPLUS on your home machine and point it at localhost:$oracle_port.
Forgive me on the $oracle_port part, I'm not an oracle guy! Substitute appropriately.

Can't ssh into Amazon AWS from Office CentOS

I have Windows and using cygwin.
I have an Amazon Ubuntu instance I can log in just fine from my system using
ssh -i keyfile \ username#AmazonHost.
However when I ssh to a CentOS server I have at my office and try to SSH to the Amazon instance from there using the same commands I always get a public key error. I have copied my keyfile over and set permissions to chmod 400 just like I did on my Cygwin client. Also on the CentOS I verified I can access the amazon instance over port 22(telnet AmazonHost 22).
Is there some other configuration on the CentOS or Office firewall that needs to be done to allow me to connect to Amazon?
If you get a public key error on one machine and not the other, then the two secret keys are different, even though you think they are the same. (Unless one machine's ssh client is totally broken.)
The file might have been corrupted in transit, but since one of the machines is Windows (though with Cygwin) and the other is Linux, my guess is that something went wrong with line endings when the key was copied from one to the other. The keys are usually encoded as text (that's how Amazon's console does it), and are fairly immune to line ending changes, but this seems to be a possible cause.
How did you transfer the file from one machine to the other? If you can adjust it, try the transfer once in binary mode and once in text mode, to see if either works. Also, just look at the files on each machine in a text editor. Do they look the same?