Skip to content

Instantly share code, notes, and snippets.

@hpbonfim
Created September 29, 2023 00:41
Show Gist options
  • Save hpbonfim/39f0cc1b85b3a8299fb98fe6c3d440dc to your computer and use it in GitHub Desktop.
Save hpbonfim/39f0cc1b85b3a8299fb98fe6c3d440dc to your computer and use it in GitHub Desktop.
Campinho Digital - Connect Vocareum Labs

Como conectar no labs via WSL

  1. Baixar o arquivo labsuser.pem do site https://labs.vocareum.com/ e salve na pasta padrão "Downloads" do Windows
  2. Dentro do WSL, execute o script sh move_pem.sh e depois sh connect_labs.sh <PUBLIC_IP>
#!/bin/bash
pemFileName="labsuser.pem"
sshAccount="ec2-user"
sshPublicIp="$1"
if [ -z "$1" ]; then
echo "You need to pass the public ip as argument"
exit 1
fi
echo "Checking if file exists..."
checkLocalFile() {
if [ -e "${pemFileName}" ]; then
echo "File exists in ${pemFileName}"
return 0
else
echo "File does not exist"
exit 1
fi
}
# connect into labs via ssh
connectLabs() {
echo "Connecting into labs... ${sshPublicIp}"
ssh -i "${pemFileName}" "${sshAccount}@${sshPublicIp}" -o StrictHostKeyChecking=no -o ConnectTimeout=2
}
if checkLocalFile; then
connectLabs
else
echo "Error"
fi
#!/bin/bash
pemFileName="labsuser.pem"
originalFileLocation="/mnt/c/Users/Henrique/Downloads/${pemFileName}"
echo "Checking if file exists..."
# check if file exists in the original location
checkOriginFile() {
if [ -e "${originalFileLocation}" ]; then
echo "File exists in ${originalFileLocation}"
return 0
else
echo "File does not exist in ${originalFileLocation}"
exit 1
fi
}
# check if file exists in the local location
checkLocalFile() {
if [ -e "${pemFileName}" ]; then
echo "File exists in ${pemFileName}"
return 0
else
echo "File does not exist"
return 1
fi
}
# move the file to the local location and give permissions
moveFileAndGivePermissions() {
echo "try to moving the file..."
mv "${originalFileLocation}" "${pemFileName}"
echo "Running chmod 400 permissions..."
chmod 400 "${pemFileName}"
echo "File moved and permissions 400 given"
}
# remove the file from the local location
removeFile() {
echo "Removing file..."
rm -f "${pemFileName}"
}
# run the scripts
if checkOriginFile; then
if checkLocalFile; then
removeFile
moveFileAndGivePermissions
exit 1
else
moveFileAndGivePermissions
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment