SSH into Your CircleCI Server
1. Generate a set of SSH key pair in your server
You would need a public and private of SSH key, theoretically it can be generated in any computer as you like. The following is a sample to generate the key.
ssh-keygen -t rsa -b 4096 -C "nicholas@example.com"
2. Add your public key as an authorized key in your server
If your key is generated in the server side, run the following key to
cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
3. Add your private key into CircleCI
Copy the content of your private key, open your circleCI project, go to `Setting > SSH Permission`, add new. Paste your key.
4. Inject SSH fingerprint into your config script
After step 3 you will see the fingerprint of your key in the page. Copy it and use it in the following script. Also add a script to make your server a known host.
- add_ssh_keys:
fingerprints:
- "a2:e5:14:ca:27:8b:f2:fc:b1:ed:80:0c:68:04:a4:8a"
- run:
name: Make remote server a known host
command: ssh-keyscan username@hostname >> ~/.ssh/known_hosts
5. After that you can SSH to your server.
ssh username@hostname 'mkdir -p /home/shared/artifacts'