SCP File from local to Heroku Server - linux

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.

Related

How to display the webapp which is running in local host of a server in my laptop's browser

I have to say that, I am not a web developer and I don't know anything about how a web application works.
I've connected to a remote server via ssh, downloaded a project (Python, flask app) from github and run it there:
zwlayer#personalcomputer $ ssh myusername#ku.edu
myusername#ku.edu $ git clone https://github.com/.../project
myusername#ku.edu $ cd project
myusername#ku.edu $ env FLASK_APP=app.py FLASK_ENV=development env USE_CUDA=False flask run --host=0.0.0.0
Now, is it possible to get interact with that through my browser from my personalcomputer ?
You can use local port forwarding in SSH.
SSH to the server with command:
ssh -L 5000:127.0.0.1:5000 myusername#ku.edu
This will forward port 5000 on your host to port 5000 on the server
Run app with command:
flask run --host=127.0.0.1 --port=5000 (host and port options are used for the purpose of explicitness)
and you should be able to access the application by entering http://127.0.0.1:5000 in your browser.
Read more at https://www.booleanworld.com/guide-ssh-port-forwarding-tunnelling/
When starting a Flask development server using flask run, it starts listening on the loopback interface on port 5000 by default. By adding --host=0.0.0.0 you make the flask server listen on all network interfaces of the host. So, if you have full network access to the host, you should be able to point your browser to it. With the addresses given in your question, just enter http://ku.edu:5000 into the address bar of your browser to interact with your Flask web application.
However, this is not recommended, for security reasons! Since the server is listening on every network interfaces, any person with network access to the host computer can access the application. You're running the application with the Flask development server in development mode, which is not safe for production use.
Instead, I would suggest to use ssh port forwarding to access the flask development server, bound to the loopback interface of the remote host:
zwlayer#personalcomputer $ ssh -L 5000:localhost:5000 myusername#ku.edu
myusername#ku.edu $ git clone https://github.com/.../project
myusername#ku.edu $ cd project
myusername#ku.edu $ env FLASK_APP=app.py FLASK_ENV=development env USE_CUDA=False flask run
This way, ssh forwards all traffic directed to port 5000 of your local computer through the ssh tunnel to localhost:5000 at the remote host, i.e. to port 5000 of the remote host itself.
So, you can point your browser to http://localhost:5000, which is forwarded to the remote server's localhost:5000, which is where your flask server is listening. But—in contrast to the above solution—only local or ssh users at the remote host can access your application.

How can I access my nodejs web server from my local computer using the server domain name?

I installed nodejs and created a sample app. When I run npm start I get a message saying that I can open my web browser to http://localhost:3000 to see the app in action, but this installation is on a web server - not my local computer, so, instead of localhost:3000 I want to get there using something like mydomain.com:3000
I can't find the answer, it's very likely I just don't know how to search for it... any ideas?
I'm following the tutorial here: https://facebook.github.io/react/tutorial/tutorial.html
I think I only needed to get away from this for a while. I got it working using ssh local forwarding.
I already used an ssh config file to log in to my server without having to remember the password, so I just added this line to my config file:
LocalForward localhost:3000 xxx.xxx.xxx.xxx:3000
where xxx.xxx.xxx.xxx is my server IP address.
Then, I connected to my server via ssh:
ssh -f -N mysite
Once connected, I open up the browser and go to localhost:3000 and there it is now.
I used my ssh config file, but it should also work without it.
ssh -f -N -R 3000:localhost:3000 mydomain.com
I found this command that eventually led me to solve my problem in this link: http://stuff-things.net/2016/01/20/tunneling-to-localhost/

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

Git hooks may need higher privileges

I'm using node.js for my webserver, and I would like forever (or something like it) to run the server.
I'm also using git to manage the website. I have a bare repository on the server that I can push to/pull from on my local machine. I would like the repository to do three things when I push to it.
CD to my working directory (on the server)
Have the working directory pull from the bare repo
Restart the running webserver.
The following script seems like it's what I should use as a post-receive hook in my bare repo.
cd ~/site
git pull
sudo forever stopall
sudo forever start main.js
However, I don't think it's smart to have the git hook use sudo like that. The script needs elevated to run on port 80.
How should I be doing this? What should my git post-receive look like?
Thanks!
Well, for my particular case, it turns out I shouldn't be running node as a super user for security reasons. I wanted it to be elevated to run on port 80, but it didn't need to be elevated to run on port 8000.
So I forwarded port 80 to port 8000, and now am running node on port 8000. It still works identically to how it did before.
The command that I used in particular to forward port 80 to 8000 is
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000

How can I find where node.js is running?

I have a VPS with node.js installed, I already uploaded a basic example to test it on the server, so I tried doing this:
I access by SSH, navigate to my project folder and run
node app.js
I get this message
Express server listening on port 8080
I thought i could see my app here
example.com:8080 or server.example:8080... but nothing. Then I tried with the info from os.networkInterfaces(); and os.host(); and still nothing happen
could you help me out? as you can see I am a total noob on node.js. What I'm doing wrong? or what should I do before running my app? Something related to DNS's? i have no idea
How do you ssh to your host? with ip or name? Is it something like:
ssh root#example.com
if so then at least you know your DNS is ok.
Once on the server do a
netstat -a
if you find *:8080 then your server is listening in the default ip. If you see something like 12.23.45.67:8080 then this number is the ip your server is listening.
ifconfig
will give you the servers ip. This should be the same as the ip of example.com. If not then maybe there is some router/firewall in front of your server and you have to configure that to allow port 8080 to reach your server.
if someone ever has the same problem this is how i solved on CentOS:
Open this file
/ Etc / csf / csf.conf
Add the required port
Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,26"
Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,37,43,53,80,110,113,443,587,873"
Restart
# # Csf-r

Resources