 I have a web server here with this domain name that is hosting a website that is pretty much just one line of code that says hello world and the website is being hosted here under this one file index.html and the code is also hosted here on github where most of the development happens so whenever someone makes a change to the code they will push the change to github and then i'll have to manually download the code again and redeploy it to the web server to port the changes over and today we're going to take a look at how we can automate this process github actions will allow github to automatically port the changes from a github repository whenever someone makes a push to it directly to your deployment server via a protocol called sftp so to do that you have to click on the actions tab on your repository click set up a workflow yourself and here you're gonna have to copy and paste some code into this new file here this code will be in the video's description so you can just go to that link and copy and paste it into your github repository so there are a few things here that you have to change mainly the username you have to change the username here to the username of your linux server that is hosting the website and for a server you have to change this to your server's domain name or the ip address that your server is running on the port is always port 22 as the default ssh port now if you've changed that to a non-standard port then you have to define that here and the ssh private key is basically a method of authenticating github to make changes on your deployment server so for this we're going to have to generate an ssh key pair and to do that we're going to have to open up a terminal session here if you're on the windows it's command prompt so run the command ssh dash key gen dash t rsa so hit enter and just hit enter again to accept the default location to save the key to and the passphrase will just be empty so i'm just going to hit enter and enter again so now what this has done is that it has generated a key pair in this location and so i'm going to cd into that location by typing cd space tilde slash dot ssh and i can do a simple ls and you can see that there's the key pair there so the id underscore rsa.pub file is the public ssh key that you're going to want to copy over to your deployment web server and the id underscore rsa file is the private key that you want to copy over to github so github gets its own key and the server gets its own key and so that's how the key pair authentication works so i'm going to type open dot which will open this location in my file manager and you're going to want to open an sftp or ftp connection to your web server to be able to modify the files there so go to your home directory and create a new folder called dot ssh if it's not already created so new directory dot ssh you can use any ftp client like file zilla or cyberduck it doesn't matter or you could just use your control panel if you have one installed create that ssh folder and create a new file called authorized underscore keys and what you're going to put in this file is that public key that you have just created so i can just drag this and drop it there and you will automatically copy the contents of the file in here and click save and that's done so now i have a file called authorized underscore keys that is basically the same file as this id underscore rsa.pub key on my server but that's just the public key we still need to put the private key into the github repository so github is authorized to make changes on the server so go to your settings tab of your github repository and scroll down until you can see secrets and click on that and click new repository secret this is where we're going to put our private key so i'm going to open up my file manager again where we've generated that private key and i'm going to open this with a simple text editor and just copy everything of that file and paste it here in github uh you can name this key whatever you want but i strongly suggest you to name this ssh underscore private underscore key all caps lock because if i go back to the file that we were editing earlier on you can see that it says here secrets dot ssh underscore private underscore key so if you were to change the name of your private key here you have to change it here as well so don't forget about that once that is done you can go and hit add secret and once the secret is added we just have to go back to our file that we were editing and look at the local path here if you leave local path as the default value this will clone the entire github repository to your remote server now if you want to clone just a portion of your repository you can customize this to your needs and the remote path is basically the target the target location in your remote server that you want to clone your repository to now the default value here is the location of the Apache web server but i have a customized location that i want to put and it's slash home slash username slash um public underscore html so that's going to be my custom remote path and args is basically just sftp arguments you can leave that as default once you're done hit start commit and commit a new file now immediately after we've committed this file we can go to the actions tab and monitor the progress so everything is working right now and just to demonstrate to you that it's working i'm going to edit this file right here so basically the file uh it just says hello world right now on this um server if i go and edit this file on github i change this to hello and hit commit changes uh and give it about like one minute for it to deploy to the web server and i'm going to go to the actions tab just to be sure it has completed so it is done i can see a green tick there so i'm going to go to my web server and reload the page and you can see that instantly we see the changes made to the server without us even going to the server's directory and modifying the public underscore html file ourselves so this is how you use github actions to automatically deploy your repositories to the web server and although it's a little bit complicated to set up what we thought of the ssh key pairs it's still definitely worth it in the long run