Set Up SSH Keys (for repo deploy)
1
| ssh-keygen -t rsa -b 4096 -C "copy0401@gmail.com"
|
1./Users/電腦使用者名稱/.ssh/id_rsa_deploy
2.輸入密碼 留白 Enter
3.再次輸入密碼 留白 Enter
會產生一組金鑰
公鑰: id_rsa_deploy.pub
私鑰: id_rsa_deploy
( 私鑰base64編碼: id_rsa_deploy_base64
後面會介紹 )
github repo add deploy key
in copy0401/copy0401.github.io
Settings
> Deploy keys
> add deploy key
Title: travis deploy
Key: 填入 id_rsa_deploy.pub
公鑰內容
1
| ssh-rsa AAAAB3NzaC1yc2EA...gzR7LH/iSxYwxSbb9+Q== copy0401@gmail.com
|
github token (public_repo)
github.com > your_settings
>Developer settings
> Personal access tokens
> Generate new token
note: Travis access
Select scopes : public_repo
Generate token = > 123a1c1ed1dfa1fc1234b123456a12abd1234567
GH_TOKEN
1
| travis encrypt 'GH_TOKEN=123a1c1ed1dfa1fc1234b123456a12abd1234567' --add
|
or
1
| travis encrypt 'GIT_NAME="copy0401" GIT_EMAIL=copy0401@gmail.com GH_TOKEN=123a1c1ed1dfa1fc1234b123456a12abd1234567' --add
|
.travis.yml
中增加 GH_TOKEN=[secure]
1
2
| travis login --pro --auto
travis encrypt SOMEVAR="secretvalue" --add
|
.travis.yml
中增加 SOMEVAR=[secure]
To generate secure SSH deploy key for a github repo to be used from Travis
參考: https://gist.github.com/floydpink/4631240
1
| base64 --break=0 ~/.ssh/id_rsa_deploy > ~/.ssh/id_rsa_deploy_base64
|
id_rsa_deploy
轉換為base64編碼為 id_rsa_deploy_base64
1
| ENCRYPTION_FILTER="echo \$(echo \"- secure: \")\$(travis encrypt \"\$FILE='\`cat $FILE\`'\" -r copy0401/copy0401.github.io)"
|
1
2
| brew install coreutils
gsplit --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" ~/.ssh/id_rsa_deploy_base64 id_rsa_
|
會產生約46行內容 貼到 .travis.yml
最後面 注意格式,前面加 -
1
2
3
4
5
6
7
8
9
| env:
global:
- secure: "rpdVrWM...xtOuONAE="
- secure: "aJGiNmI...nzpD62Sk="
- secure: "O1rEHB...Yu+xXGFQc="
.
.
.
- secure: "O1rEHB...pDCdFd3d="
|
修改 .travis.yml
內容
在 before_script:
下面增加這幾行內容
1
2
3
4
5
| before_script:
- echo -n $id_rsa_{00..30} >> ~/.ssh/id_rsa_base64
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
| env:
global:
- GH_REPO="copy0401/copy0401.github.io" # 依照自己的 github_name/github_repo 設定
- secure: "rpdVrWM...xtOuONAE=" # 解析後就是 GH_TOKEN
- secure: "x87sdje...in0xdase=" # 解析後就是 SOMEVAR
- secure: "aJGiNmI...nzpD62Sk=" # 解析後就是 id_rsa_00
- secure: "O1rEHB...Yu+xXGFQc=" # 解析後就是 id_rsa_01
- secure: "nzpD6ec...xtOuONAE=" # 解析後就是 id_rsa_02
.
.
.
- secure: "nzpD6ec...xtOuONAE=" # 解析後就是 id_rsa_45
|
1
2
3
| travis encrypt 'GH_TOKEN=123a1c1ed1dfa1fc1234b123456a12abd1234567' --add
travis encrypt SOMEVAR="secretvalue" --add
gsplit --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" ~/.ssh/id_rsa_deploy_base64 id_rsa_
|
修改內容 .travis.yml