github.com/shohhei1126/hugo@v0.42.2-0.20180623210752-3d5928889ad7/docs/content/en/hosting-and-deployment/deployment-with-rsync.md (about) 1 --- 2 title: Deployment with Rsync 3 linktitle: Deployment with Rsync 4 description: If you have access to your web host with SSH, you can use a simple rsync one-liner to incrementally deploy your entire Hugo website. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-02-01 8 categories: [hosting and deployment] 9 keywords: [rsync,deployment] 10 authors: [Adrien Poupin] 11 menu: 12 docs: 13 parent: "hosting-and-deployment" 14 weight: 70 15 weight: 70 16 sections_weight: 70 17 draft: false 18 aliases: [/tutorials/deployment-with-rsync/] 19 toc: true 20 notesforauthors: 21 --- 22 23 ## Assumptions 24 25 * Access to your web host with SSH 26 * A functional static website built with Hugo 27 28 The spoiler is that you can deploy your entire website with a command that looks like the following: 29 30 ``` 31 hugo && rsync -avz --delete public/ www-data@ftp.topologix.fr:~/www/ 32 ``` 33 34 As you will see, we put it in a shell script file, which makes building and deployment as easy as executing `./deploy`. 35 36 ## Install SSH Key 37 38 If it is not done yet, we will make an automated way to SSH to your server. If you have already installed an SSH key, switch to the next section. 39 40 First, install the ssh client. On Debian/Ubuntu/derivates, use the following command: 41 42 {{< code file="install-openssh.sh" >}} 43 sudo apt-get install openssh-client 44 {{< /code >}} 45 46 Then generate your ssh key by entering the following commands: 47 48 ``` 49 ~$ cd && mkdir .ssh & cd .ssh 50 ~/.ssh/$ ssh-keygen -t rsa -q -C "For SSH" -f rsa_id 51 ~/.ssh/$ cat >> config <<EOF 52 Host HOST 53 Hostname HOST 54 Port 22 55 User USER 56 IdentityFile ~/.ssh/rsa_id 57 EOF 58 ``` 59 60 Don't forget to replace the `HOST` and `USER` values with your own ones. Then copy your ssh public key to the remote server: 61 62 ``` 63 ~/.ssh/$ ssh-copy-id -i rsa_id.pub USER@HOST.com 64 ``` 65 66 Now you can easily connect to the remote server: 67 68 ``` 69 ~$ ssh user@host 70 Enter passphrase for key '/home/mylogin/.ssh/rsa_id': 71 ``` 72 73 And you've done it! 74 75 ## Shell Script 76 77 We will put the first command in a script at the root of your Hugo tree: 78 79 ``` 80 ~/websites/topologix.fr$ editor deploy 81 ``` 82 83 Here you put the following content. Replace the `USER`, `HOST`, and `DIR` values with your own: 84 85 ``` 86 #!/bin/sh 87 USER=my-user 88 HOST=my-server.com 89 DIR=my/directory/to/topologix.fr/ # might sometimes be empty! 90 91 hugo && rsync -avz --delete public/ ${USER}@${HOST}:~/${DIR} 92 93 exit 0 94 ``` 95 96 Note that `DIR` is the relative path from the remote user's home. If you have to specify a full path (for instance `/var/www/mysite/`) you must change `~/${DIR}` to `${DIR}` inside the command line. For most cases you should not have to. 97 98 Save and close, and make the `deploy` file executable: 99 100 ``` 101 ~/websites/topologix.fr$ chmod +x deploy 102 ``` 103 104 Now you only have to enter the following command to deploy and update your website: 105 106 ``` 107 ~/websites/topologix.fr$ ./deploy 108 Started building sites ... 109 Built site for language en: 110 0 draft content 111 0 future content 112 0 expired content 113 5 pages created 114 0 non-page files copied 115 0 paginator pages created 116 0 tags created 117 0 categories created 118 total in 56 ms 119 sending incremental file list 120 404.html 121 index.html 122 index.xml 123 sitemap.xml 124 cours-versailles/index.html 125 exercices/index.html 126 exercices/index.xml 127 exercices/barycentre-et-carres-des-distances/index.html 128 post/ 129 post/index.html 130 sujets/index.html 131 sujets/index.xml 132 sujets/2016-09_supelec-jp/index.html 133 tarifs-contact/index.html 134 135 sent 9,550 bytes received 1,708 bytes 7,505.33 bytes/sec 136 total size is 966,557 speedup is 85.86 137 ```