Automatic deployment from GitHub to server via SFTP (GitHub Actions)
Vložit
- čas přidán 7. 09. 2024
- Automatically push GitHub repositories to your deployment server via SFTP.
*Requires GitHub actions and SFTP to be configured
Works on any deployment server platform/VPS as long as SFTP is configured (i.e. NGINX, DigitalOcean, Google Cloud Platform, AWS, Vultr)
Workflow code: pastebin.com/q...
(Must be placed at `.github/workflows`)
Simple, quick, working: only 1 out of 100 youtube tutorials are like this! Thanks!!!
This is the most helpful tutorial I've seen on this subject. Thank you very much !!!
Yea I've spent hours trying to figure it out at first too I'm glad it helped you
This looks like it will be the exact script I need.
100% best vid on doing this. And I for one appreciate how fast you move. I hate drawn out tutorials. Finally got up and running after following this. THANK YOU!!!
Your tutorial got me 95% there. The only reason for the missing 5% is time. I had to update checkout version and will have to create encryption key pair without a password as the sftp code cannot handle key and pass together. Thank you!
thank you very much! You are the only person who helped me in this question!
Excelent video!!! It worked right away! Thank you!
Very Useful Video Content. Thank You.
Best CI that I can ever imagine ! Tanks a lot !
Hello, i really like your tutorial, but when i deploy the code with github, i get a permission denied error.
Thank you for this video.
with this method only the changed files are uloaded or all the files of the progect?
Probably all the files
JUST PERFECT!
Thank you!
I've followed each and every step but its not working. I am having an error under "deploy file" when the action runs. Here is the error
"Load key "../private_key.pem": invalid format"
host: Permission denied (publickey,password).
can you kindly help me out with that?
Are you getting this error from the GitHub console, or the terminal of your server?
Have you tried deleting all the SSH keys and regenerating them? You'll also need to make sure you don't mess up the private/public key and interchange them accidentally
You need to explicitly force the PEM like this: ssh-keygen -m PEM when generating a new key pair as described here.
github.com/wlixcc/SFTP-Deploy-Action/issues/1
same here
@@maxwelladapoe8001 thank you it works
Stupid question : would it be possible to use github as the server in FTP ?
Awesome video! I am still new to github so my question might be off but I will give it a go. I have added a .gitignore file to my root folder and when this workflow starts it doesnt "listen" to the rules of the .gitignore file. I want to ignore the same files and folders in this action as I do in the file. Is that possible?
thanks a lot man!
btw one thing extract i want to do i want to build a jar and them transfer jar a particular directory of my remote server, how that can be done?
Do i need to manually install git on the remote server?
I have done everything as You showed in this video, but I got the following error on the fourth step (SFTP Deploy):
remote open("/var/www/html/index.html"): Permission denied
I have changed the user permissions, now it works fine! Thanks :)
sudo chown -R user:user /var/www/html/
Worked dude, thank you :D
Nice @Krolik
It was very helpful to me. Thanks a lot!
It was working well for me but when I ran the workflow, I got an error of permission denied, yet I gave myself all permissions. I would like to deploy to one of my subdomains. How do I fix this please?
Permission denied from your Linux terminal?
@@ravenjs I also get
Load key "../private_key.pem": invalid format
Permission denied, please try again.
Permission denied, please try again.
Followed everything exactly.
@@ihenners_ follow the comment of @shaharyardmg7556
this tutorial is very helpful to me
I have a Question
If i have to run any command with this script after pull data how can i do ?
Data isn't pulled, it's pushed here. So GitHub Actions is taking your repository, checks it out, loads the script by this random Chinese guy called wlixcc that provides the SFTP functionality, hands over your settings including your key to that software, which should then connect to your server and push the files onto it.
So as SFTP uses SSH to connect to that server, there are 2 options: This connection is limited to SFTP only, in that case you can not run any commands on that webserver. Or you can connect with SSH. In that case you maybe should think about using rsync instead of SFTP. But then you can also connect via SSH and could run other commands. It's less save, though as someone who has your key, then can execute any command with that key. The risk of privilege escalation is really high in that case. So only use SSH access if you really really trust all the software, that has access to that private key or find another way to execute commands on that server.
Hi, thanks for sharing this.
I have one problem. It is that when I delete a file on my repo and then push it in. That file on my server does not get deleted. Does anyone else have the same problem?
Also, how can I pull changes from the server? Thanks.
I'm also facing same thing ,Have you got any solution for that?
@@sibinjames9994 still no :(
I just try to make everything to work before pushing it.
@@timdang7978 This tutorial uses the GitHub Action from this random Chinese guy calles wilxcc who has provided an option for that on the README file in the repo: github.com/wlixcc/SFTP-Deploy-Action
As described there, you can set the delete_remote_files option, which "will delete all files in the remote path before upload". So if the Upload fails afterwards, that files on the server are gone. If someone accesses the page while deployment, the page is maybe as well not available for a short period of time. It would be better if this action would be more intelligent and recognizes which files are still needed and not deleting everything, but that is not implemented here, as it seems.
Is it possible to update multiple Servers with this method?
yes i believe it's possible to modify the job script so that it updates multiple server at once :)
@@ravenjs i dont think that this solution is recommendable in terms of data security
I followed what you just did, but I got stock in this part. I'm not sure where did it go wrong when I'm just following what you did.
kex_exchange_identification: read: Connection reset by peer
I have SFTP but don't have SSH key, with password not working.
You are basically using an GitHub Action that does the deployment for you. It's an action from wlixcc which is just a random guy from China. Have you checked it? How do you protect yourself against that person changing the code and just stealing your keys?
That's what I thought also haha
hi, Awsome video, can i acces instead of an ssh key with a username and password?
Haha this is what i tried to do too initially.. but i failed :(( pls do teach me if you manage to figure it out!
woow thank you, how can i add some npm commands before deployment?
If you look at the code in the pastebin, you can see that under '-jobs', there's only a single job called "SFTP Deploy".
If you want to add more build/testing jobs you can do so in the 'jobs' section but you'll need some prior knowledge about GitHub Actions; I'll paste a link below to GitHub's docs to see if it helps you
docs.github.com/en/actions/guides/building-and-testing-nodejs
@@ravenjs many thanks, I did it and it works fine, now i can make sass changes on github and then deploy it via ssh
@@dddobriak that's great 👍