Como conectar no labs via WSL
- Baixar o arquivo
labsuser.pem
do site https://labs.vocareum.com/ e salve na pasta padrão "Downloads" do Windows - Dentro do WSL, execute o script
sh move_pem.sh
e depoissh connect_labs.sh <PUBLIC_IP>
Como conectar no labs via WSL
labsuser.pem
do site https://labs.vocareum.com/ e salve na pasta padrão "Downloads" do Windowssh 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 |