How to proxy over ssh? - linux

I have vps server where I have access to api.telegram.org, but on my local machine I could not get it.
I'm developing long poll bot for telegram, and now I need my bot to work locally - I think I can obtain it using ssh port forwarding but I dont know how to do it - I need to be able to use api.telegram.org throw my local machine over ssh to my vps

This might help
ssh -o "ServerAliveInterval 100" -L vps_server_ip:5000:api.telegram.org:80 some_vps_server_user#vps_server
This will redirect the request coming on port 5000 of vps_server to api.telegram.org at Port 80 .
Your bot has to connect to vps_server:5000 to access api.telegram.org

Related

I can only access NodeJS server locally

My server's hosted at DigitalOcean (it's a droplet) and basically, I cannot access my NodeJS app via Internet, only server-side. It's running on port 9000, I've allowed traffic to the port via ufw and iptables, no luck. When I run curl || wget while SSH-ed to the server, I get a normal response as if everything's in order. But when I try to access the server from an another machine, I just get timed out because the server returns nothing. I've heard DigitalOcean sometimes disable connections to all ports except ssh,www and ssl, but I think I've successfully 'opened' them. Any suggestions?
This is what I get when I run netstat -tulp | grep LISTEN
Turns out my dashboard was all messed up when it comes to ports, which I forgot to check, of course, so opening them directly on the server gave no results whatsoever.

SSH Tunnel to Ngrok and Initiate RDP

I am trying to access my Linux machine from anywhere in the world. I have tried originally port forwarding and then ssh'ing in; however, I believe my school's WiFi won't allow port forwarding (every time I ran it, it would tell me connection refused). I have setup an account with ngrok and I can remotely SSH in, but now I am wondering if it is possible to RDP. I tried connecting via the Microsoft Remote Desktop app on Mac, but it instantly crashes. I have also looked at trying to connect with localhost, but it's not working. So far, I have tried (with xxxx being the port):
ssh -L xxxx:localhost:xxxx 0.tcp.ngrok.io
and
ssh -L xxxx:localhost:xxxx <user>#0.tcp.ngrok.io
but my computer won't allow it and after about 2 or 3 times, it warns me of a possible DNS Spoofing. Is there anyway that I can run a remote desktop of my linux machine that I have ssh tunneled to (from my mac) on ngrok? Thank you!
First you'll need to sign up with ngrok if you haven't already and you'll be given an authtoken. You'll need to install this by running
./ngrok authtoken <insert your token here>
This will save your token to a file located ../username/.ngrok/ngrok.yml
Then you'll need to ask ngrok to create a TCP tunnel from their servers to your local machine's Remote Desktop port which should be 3389 by default
ngrok tcp 3389
Give it 30 seconds or so then jump to http://localhost:4040/status to see what the tcp address ngrok has allocated you. It should look something like tcp://1.tcp.ngrok.io:158764
Now you should be able to remote into your machine using address 1.tcp.ngrok.io:158764

SCP File from local to Heroku Server

I'd like to copy my config.yml file from my local django app directory to my heroku server, but I'm not sure how to get the user#host.com format for heroku.
I've tried running 'heroku run bash'
scp /home/user/app/config.yml
I'm not sure how I can get it in the
scp user#myhost.com:/home/user/dir1/file.txt user#myhost.com:/home/user/dir2'
format
As #tamas7 said it's firewalled, but your local machine is probably also firewalled. So unless you have a private server with SSH accessible from the Internet, you won't be able to scp.
I'm personally using transfer.sh free and open source service.
Upload your config.yml to it:
$ curl --upload-file ./config.yml https://transfer.sh/
https://transfer.sh/66nb8/config.yml
Then download it back from wherever you want:
$ wget https://transfer.sh/66nb8/config.yml
According to http://www.evans.io/posts/heroku-survival-guide/ incoming connections are firewalled off. In this case you need to approach your local machine from the Heroku server.
heroku run bash
scp user#mylocalmachine:/home/user/dir/file.txt .
This is a bit late to answer this question, but I use services like localtunnel - https://localtunnel.github.io/www/ to copy files from local machine to heroku.
First, run a python HTTP server in the directory where the file is located.
cd /path/to/file
python3 -m http.server
This starts a server in port 8000. Configure localtunnel to connect to that port.
lt -s mylocal -p 8000
Now from your heroku machine, you can fetch the file via curl.
curl -XGET http://mylocal.localtunnel.me/myfile.txt > myfile.txt
You could also use a service like https://ngrok.com/ to open up a TCP tunnel into your local machine.
You will need to enable Remote Login as in simlmx answer.
On your local machine open the TCP tunnel just like this:
$ ngrok tcp 22
And then, on the Heroku console, just use SCP with the PORT and HOST that Ngrok provided.
$ scp -P [PORT] username#[HOST]:~/path/to/file.ext .
If you need to download your entire repo, for example to recover an app that you no longer have locally, use heroku git:clone -a myapp. Docs.
Expanding on tamas7's answer:
You can connect to your computer from the heroku server.
If your computer is behind a router, you'll also need to forward the connection to your computer.
1. You computer must accept ssh connections
On my mac it was as simple as enabling it in the Preferences / Sharing panel.
2. Your router needs to forward the connection to your computer.
Go to your router's settings page in your browser (typically 192.168.0.1 but varies depending on the router). Find the port forwarding section and forward some port to your computer on port 22.
This is how it looked on my tp-link:
Here I am making sure that port 22000 is forwarded to my computer (192.168.0.110) on port 22.
3. Find your external IP
Simply google "what is my IP".
4. Scp your file from heroku
heroku run bash
scp -P 22000 your_user#your_external_IP:/path/to/your/file .
5. Undo everything!
Once you're done it's probably good practice to disable the port forwarding and remote login.

Accessing application in browser over SSH proxy on localhost.

I have SSH access to a web server that is hosting an application on port 8080. I have a SSH session setup and a proxy configured on Chrome to redirect requests to SSH tunnel. I basically configured it using these instructions: http://drewsymo.com/2013/11/ssh-tunnel-in-30-seconds-mac-osx-linux/
I can confirm using Whats My IP that my IP is that of the SSH session and that is working correctly.
But I cannot figure out how to access the local application on the web server that I am SSHed into. When I try localhost:8080 the SSH session gives me an error "channel X: open failed: connect failed: Connection refused"
Any idea what is going on?
You can just create a port-specific tunnel:
ssh -L18080:localhost:8080 username#theothermachine
and then go to localhost:18080 on your local machine. The tunnel will forward your request to port 8080 of the localhost on the other end (and of course, localhost on the other end is the other machine itself). If that doesn't work for some reason, then replace localhost by 127.0.0.1 in the ssh command.

How should my local server communicate with an EC2 server?

I have a node.js server running on ec2. I'd like for that server to automatically push data to another node.js server that is running on my laptop.
What is the best way to do something like this?
You could use a service like showoff.io to create an entry point to access your local laptop, or you could just create an SSH tunnel by running this command on your laptop:
ssh -R port:localhost:remoteport ec2-host
That will allow port on the loopback interface of your EC2 server to connect to remoteport on your laptop.
Then just modify your code to connect to the node.js program running on your laptop via the IP of 127.0.0.1 and port of port.
You could have the EC2 node.js call a function from the local node.js, and pass the data as variables

Resources