Created
January 11, 2023 01:22
-
-
Save Ertavf/ae82480d24529b2816c47ea62dffeafd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
<<nedirkibu | |
webde ara: https://www.google.com/search?q=remote+ssh | |
webde ara: https://shell.cloud.google.com/ | |
yukle: https://cloud.google.com/sdk/docs/install | |
$HOME/.ssh/config dosyani olustur, benimkisi boyle: | |
Host gcp | |
HostName "34.147.23.251" | |
User ertavf | |
Port 6000 | |
ForwardAgent yes | |
IdentityFile ~/.ssh/google_compute_engine | |
nedirkibu | |
MY_SSH_CONFIG="$HOME/.ssh/config" | |
if ! /usr/bin/gcloud cloud-shell ssh --authorize-session --dry-run | |
then | |
echo "Failed to run cloud-shell ssh" >&2 | |
exit 1 | |
fi | |
CLOUDSHELL_HOST=$(/usr/bin/gcloud cloud-shell ssh --authorize-session \ | |
--command="dig TXT +short o-o.myaddr.l.google.com @ns1.google.com" || echo "Error running dig command") | |
if [ -z "$CLOUDSHELL_HOST" ]; then | |
echo "Error: CLOUDSHELL_HOST variable is empty" | |
exit 1 | |
fi | |
# g1: It will replace only the first occurrence of the matched pattern. | |
# 1,4 btw line 1 and 4 | |
sed -i -e "1,4s/HostName.*/HostName\ $CLOUDSHELL_HOST/g1" $MY_SSH_CONFIG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment