46
loading...
This website collects cookies to deliver better user experience
ssh-keygen -o -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/sj/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sj/.ssh/id_rsa
Your public key has been saved in /home/sj/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:40XYRaLv66J9UVk1wrMVgMFQh0/BaV5OhJG2ZsOsbEU [email protected]
The key's randomart image is:
+---[RSA 3072]----+
| .=+O*O=o|
| + *.Eo+.|
| o o XoO |
| o o% . |
| S +.= . |
| . +.+ |
| . o. |
| .. .. |
| ...+o |
+----[SHA256]-----+
SSH
key pairs. Now, we can access content of our public key by using cat
command.cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDOXmwRpIsoXEQsKgw1Y43+yJ8JaU2iY1uc45pg7VcD9Pim748LcUzoa8YHF14yE6LeD9YVZcdu1PHC2xOJP5/eVzweBEFHq4onzNZZ5mO04+2WZQB72d6drJKJce+JXtHv8S3PWZQFYXA6cueBZwpiSeMI1Bu5Sz+idafsw4QY01E9JBDWOtx8d468u2uLeMl8rlFj+0uiN/K9tDlMuiH3U8B3XcH3bYBky0C2bQxeSZ4l3o/X76rt0tythOxxd/Xasw461wFQYYNYqLRZKHxryg/5uTBzOMIVXBykTzH1ffBx/BoZioBVsWeH/uPC5i6zle800MZEBylWDpHh8VBp7NBrEQEwJqPrHEtchIyiFkBSMUKoAUku2EzyT7aFxM+O0hAJMZ9wqHX0qdF0zJb0U4rMysyuAs+MVK54e6dMXqV0ai03jOde9/TibDMdeKYZ8SygxhbKH8ibNIwwoF/YtyJoqsBRiOj8R2YN/GCnijNlB8sMq6J4XRcfl7JKyp0= [email protected] ~/.ssh/id_rsa.pub
SSH
key and paste it in the 'SSH key content' Box and also give a name to your key. I am going to give 'Droplet SSH' Name to my key for this tutorial. After that click on 'Add SSH Key' Button.206.189.183.112
and in your terminal type the below command with your ipv4 address.adduser wbm
id wbm
uid=1000(wbm) gid=1000(wbm) groups=1000(wbm)
usermod -aG sudo wbm
id wbm
Command. You will see your user in sudo group.uid=1000(wbm) gid=1000(wbm) groups=1000(wbm),27(sudo)
sudo su - wbm
wbm@twitter-bot
. You can also double check by typing the below command.whoami
wbm
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
ctrl + x
and y
to save and exit.chmod 600 ~/.ssh/authorized_keys
sudo service ssh restart
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
to see the node version and confirm the installation.mkdir ~/twitter-bot
cd twitter-bot/
npm init -y
touch server.js
sudo nano server.js
const Twitter = require('twitter-lite')
let cron = require('node-cron');
const client = new Twitter({
consumer_key: "paste_your_key",
consumer_secret: "paste_your_key",
access_token_key: "paste_your_key",
access_token_secret: "paste_your_key"
});
const getTweetLikesAndUpdateProfile = async () => {
const tweetData = await client.get("statuses/show", {
id: "1315114170933628929"
}).catch(err => {
console.log(err)
})
if ("favorite_count" in tweetData && "retweet_count" in tweetData) {
const name = `SJ - this tweet has ${tweetData.favorite_count} likes and ${tweetData.retweet_count} retweets`
await client.post("account/update_profile", {
name
}).catch(err => {
console.log(err)
})
}
}
cron.schedule('*/1 * * * *', () => {
console.log('running a task every 1 minutes');
getTweetLikesAndUpdateProfile()
});
console.log('started')
API Key And Secret
in consumer_key
and consumer_secret
and Access Token & Secret
in access_token_key
and access_token_secret
Respectively.ctrl + x
and y
. After this, Open the package.json file in nano editor by running the below command.sudo nano package.json
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "start": "node server.js"
},
"author": "",
"license": "ISC",
+ "dependencies": {
+ "node-cron": "^2.0.3",
+ "twitter-lite": "^0.14.0"
+ }
ctrl + x
and y
. Next, we also need to install the node dependencies. To do that run the below command.npm install
started
in the console.npm start
ctrl + c
. It is recommended to use a service known as pm2
to run our application as a process. To install pm2
Run the below command.sudo npm install pm2 -g
pm2 start server.js
exit
command. pm2 ls
command or if you want to stop a process use pm2 stop {id}
.