DEV Community

How to setup continuous deployment of a website on a VPS using GitHub Actions

Bruce on June 08, 2020

Doesn't matter if it is a private or public repository Prerequisites Here are the prerequisites required for this tutorial: A GitHu...
Collapse
 
jfosela81 profile image
Jorge

Thanks for the article this is what I was looking for! Just for update it, now Github gives you the chance to create Environment secrets. Well, you should create Repository Secrets to follow properly this tutorial. I made that mistake and at the beginning I couldn't make it work because I created ENV secrets instead of Repo ones.

Thanks!

Collapse
 
rein96 profile image
Reinhart Andreas

Thanks for the tutorial

I got error in Copy repository contents via scp step:

the log:

tar all files into /tmp/565278366/9sTHaiaED0.tar
scp file to server.
2020/09/23 18:26:16 error copy file to dest: **, error message: dial tcp: lookup ** on 168.63.129.16:53: no such host
drone-scp error: error copy file to dest: **, error message: dial tcp: lookup ** on 168.63.129.16:53: no such host

Any ideas? Thanks before :)

Collapse
 
azrinsani profile image
Azrin Sani • Edited

Hi, I just created an account to answer this question. I was going through this problem as well. For me it turned out that I have not enabled SSH keys on my VPS

in a nutshell, make sure you have "AuthorizedKeysFile %h/.ssh/authorized_keys" in your '/etc/ssh/sshd_config' file entrt

HOW IT FULLY WORKS:

  • Every device/service(such as github), will generate a private and public key pair using SSH. In this example we are using the actual vps to generate the private-public key pair and manually copy the private key into Github.
  • The private key stays on the device/service, but the public key is copied into ~/.ssh/authorized_keys on your VPS
  • So when Github logs into you vps, it uses the private key to sign the handshake message. The VPS uses the public key to verify the signature and since it is 'Authorized' will allow login.
  • under /etc/ssh/sshd_config must uncomment 'AuthorizedKeysFile %h/.ssh/authorized_keys'
  • Finally don't forget to restart SSH => $ sudo service ssh restart
Collapse
 
rein96 profile image
Reinhart Andreas

Thanks for the help Bruce and Azrin!

Collapse
 
knowbee profile image
Bruce

Try using 168.63.129.16 as the host without port 53

Collapse
 
lebed2045 profile image
Alex Lebed 🐧

doesn't work for some reason,

tar all files into /tmp/196564759/vw1MAdYY5a.tar
scp file to server.
2021/01/04 13:45:34 error copy file to dest: ***, error message: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
Enter fullscreen mode Exit fullscreen mode
  • any ideas what's wrong?
Collapse
 
knowbee profile image
Bruce

Repeat step 4 and 5

Collapse
 
pianographe profile image
pianographe

Hello!

Thanks for sharing.
I followed your tutorial but I get an error when I try to build deploy.yml:

scp file to server.
create folder /discord-bots/pianobot
drone-scp error: stty: 'standard input': Inappropriate ioctl for device

Do you please know how to fix this? Thank you!

Collapse
 
nimit2801 profile image
Nimit Savant

Everything's working but I can't setup script in this thing
I want something like this
cd word-dir && npm i
but gives npm ain't recognized

Collapse
 
nimit2801 profile image
Nimit Savant

So basically it's not detecting npm because nvm doesn't install node in /usr/local/bin/
ref: stackoverflow.com/questions/628630...

Sol: add this two lines in your script

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
Enter fullscreen mode Exit fullscreen mode
Collapse
 
khanmaytok profile image
KhalO

Thank you, useful action

Collapse
 
chrissiemhrk profile image
Chrissie

Nice Article

Collapse
 
grezor profile image
Geoffrey • Edited

Hello, I have a problem with the keyssh on my vps.

I have my key, but I can't do this on my vps?
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Do you have a solution?

I saw that it had something to be enabled in the ssh config? Thanks

Collapse
 
kenean50 profile image
Kenean • Edited

You can print the value of your public key on you your terminal and append it to the "authorized_keys" file by just copying it.

To do this run this command "cat ~/.ssh/id_rsa.pub" on your terminal and if you saved your ssh keys on the default location you should be able to see your public key printed out.

Then just copy your public key on the terminal and open your "authorized_keys" file with the following command "nano ~/.ssh/authorized_keys" this will create the file if doesn't already exist. now past the value, you copied and save the file. if there is already a value there just add yours at the end of the file

Also make sure your ssh-agent is runing and you have add your key. (follow instructuion above )

Collapse
 
mozayntwali profile image
Ntwari Moise

Great and very insightful👍

Collapse
 
marviorocha profile image
Marvio Rocha

Thanks for the Tutorial :)

Collapse
 
ollyimanishimwe profile image
Olly

Informative

Collapse
 
knowbee profile image
Bruce

Thank you

Collapse
 
manishfoodtechs profile image
manish srivastava

+100

Collapse
 
alexandrediniz profile image
Alexandre Diniz

you saved my day!!

Collapse
 
ohbob profile image
Roberts Ozoliņš

You just made my day! Works like a charm and thank you very much for that kind sir!

Collapse
 
ohbob profile image
Roberts Ozoliņš

oh yeah i got one comment thought, i had to replace target: "/var/www/randomsite" to current user target: "~/www/randomsite" to get it working. And that's that.

Collapse
 
ulissesmeira profile image
Ulisses Meira

Thank you for the tutorial!

Collapse
 
shivang12031774 profile image
Shivang Mittal

Thank you

Collapse
 
lucad987 profile image
lucad987

remember to set permission to the destination folder in your VPS (i.e., /var/www/mywebsite) doing chwon

Collapse
 
berna39 profile image
KALEMA SHANGO Joseph

Thanks a lot for this tutorial.

Collapse
 
smyja profile image
Smyja

how do you add domain name for the folder?