Ssh into gcp server
This video explains it well - https://www.youtube.com/watch?v=fmh94mNQHQc&ab_channel=storagefreak
When you have your instance running, first thing is make sure firewall rules accept the traffic.
1 Networking -> VPC network -> Firewall
If you did not create any rules yet, there should be one named "default-allow-ssh". Port 22 on protocol tcp is open to the internet.
If it's done once, you don't have to do it again for each machine
2 Compute Engine -> Virtual Machines -> VM instances
Get the external ip and try to connect via putty.
If you see the login screen, the "login as:" - thats a first good sign indicating that nothing is wrong from my or gcp side in terms of firewall.
But if you try to enter any username, you get a warning, which basically means that username/password authentication is disabled and we must use ssh key to authenticate.
3 Generate public/private key pair
3.1 Generate key pair over PuTTYgen
Open PuTTY Key Generator
or PuTTYgen
to generate one RSA key 2048 bits
.
Save public and private keys on desktop somewhere in a separate folder with today's date.
Copy the "Public key for pasting into OpenSSH authorized_kays file:" part, we will use it in GCP ssh key row.
Key comment - this is your USERNAME! you want to use to connect to your machine
3.2 Generate key pair over WSL
Creating a new SSH key specifically for connecting to your GCP VM and storing it in GCP is a good approach. This way, you can generate a new key pair within WSL and configure GCP to use the public key for authentication.
Open your WSL terminal:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
cat ~/.ssh/mykey.pub
Copy the entire contents of the public key that is displayed in the terminal.
4 Add the public
key to your GCP project:
- Go to the GCP Console
- Navigate to the project containing your VM instance.
- Open the VM instances page and select your target VM.
- Click the "Edit" button at the top of the page.
- Scroll down to the "SSH Keys" section.
- Click "Add item".
- Paste the copied public key into the "Enter entire key data" field.
- Click the "Save" button to add the key.
GCP now will automatically login to the machine, create a user with your chosen username and add the ssh key. (can check this in logs, the same ssh page)
5 Connect to the GCP VM using the new SSH key
5.1 Over putty
- Take the external ip, put it into the Host Name field in putty, port 22.
- Then go to SSH -> Auth -> Credentials to authenticate with
- Choose the private key, in my case itÅ› on my desktop
- try to login
- enter your username(same as you gave when creating the ssh key)
- you should be logged in
- sudo su - to login as root
5.2 Over wsl
In your WSL terminal, use the ssh command followed by the username and IP address or hostname of your GCP VM:
user is a first user gcp created for me, which is arvydas.gaspa(saw it in logs). host is - 34.88.9.236
test if it works - ssh -T git@github.com
ssh -i ~/.ssh/mykey user@host
for example:
ssh -i ~/.ssh/arvydas_gcp_20230709 arvydas.gaspa@34.88.9.236
Replace mykey with the name you provided for the PRIVATE key pair, user with the appropriate username, and host with the IP address or hostname of your GCP VM.
Erm I am still not able to paste into vim :confused:
At least can now paste with ctrl+v and such.
Can change wsl terminal options, but no option to select right click for paste.
but then I right click paste into the wsl terminal.. krc..
tai geriau jau naudoti putty ir rasyti rankyte viska i vim.
In nano it works.
Adding set mouse=a might have helped for vim also. cool.