ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jlynch/.ssh/id_rsa):
For example:
/Users/jlynch/.ssh/crontastic_key
ls ~/.ssh/
new ssh key section (when creating the droplet, click new SSH key
cat /Users/jlynch/.ssh/crontastic-key.pub
pbcopy < ~/.ssh/id_rsa.pub
Setup Github SSH Key
Tunneling Into The Server
ssh-add -l
ssh-add ~/.ssh/crontastic-key
Adding A New User
adduser ubuntu
usermod -aG sudo ubuntu
mkdir /home/ubuntu/.ssh
cp .ssh/authorized_keys /home/ubuntu/.ssh/
chown ubuntu.ubuntu /home/ubuntu/.ssh/authorized_keys
chmod 644 /home/ubuntu/.ssh/authorized_keys
New Key Way
sudo ssh-keygen
sudo chown ubuntu.ubuntu /home/ubuntu/.ssh/crontastic_gh /home/ubuntu/.ssh/crontastic_gh.pub
Enable UFW Firewall
First, run this to make sure you are using OpenSSH:
Then run this command to allow OpenSSH (so that you don't lock yourself out of your own server! hehe)
ufw allow OpenSSH
ufw enable
Login As New User
Getting the Code
mkdir Git-Projects
git --version
ssh-add -l
eval $(ssh-agent)
In this case, let's call ssh-add with out authorized keys file.
shh-add /home/ubuntu/.ssh/crontastic_gh
Now, let's clone the project (make sure to use the SSH url provided by the "clone or download" button on Github and not the HTTPS one).
git clone [email protected]:JimLynchCodes/Ameritrader-Bots.git
Automatically Adding the Key to Your Keychain On Session Login (And Automatically Revoking It On Logout)
# Re-Add shh agent agentpid=$(ps -ef | grep -P [s]sh-agent | awk '{print $2}') if [[ $agentpid ]]; then export SSH_AGENT_PID=$agentpid sock=$(ls -1 /tmp/ssh-*/agent.* | head -1) export SSH_AUTH_SOCK=$sock else eval $(ssh-agent -s) ssh-add ~/.ssh/crontastic_gh &> /dev/null fi
node -v
npm -v
However, after naively taking the advice of this output I run the command and get the error that apt was, "Unable to locate package nodejs".
The issue was that I needed to update apt first:
sudo apt update
sudo apt install nodejs
sudo apt install npm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
exit
nvm --version
Testing The Cron Scripts On The Server
nvm use
nvm i v13.13.0
npm i
Scheduling the Cron Jobs
crontab -l
crontab -e
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]:
Staying Organized With Your Logs
mkdir /home/ubuntu/Logs
Fixing Some Node Permissions Issues
which node
ls -al /home/ubuntu/.nvm/versions/node/v12.16.1/bin/
chmod 777 /home/ubuntu/.nvm/versions/node/v12.16.1/bin/node
Fixing NVM Permissions Issues
ls -al /home/ubuntu/.nvm/
chmod 777 /home/ubuntu/.nvm/nvm.sh
Updating the Date And Timezone
date
timedatectl list-timezones | grep New_York
timedatectl set-timezone America/New_York
Now Set It Loose
And of course you can always come back and use this post as a reference. ?
Happy coding!