How Do You Log into a Linux Server in Google Cloud Platform?

Problem scenario
You created a Linux VM in GCP.  How do you get credentials to connect to it?  What do you have to do to log in with PuTTY?

1.  Make sure the firewalls allow for the connection.  See this posting if you need to change that.
2.  In the GCP console, go to Computer Engine -> VM Instances.  
3.  Go to the VM you want to connect to.  Under the "Connect" column find the small triangle that points downward.  Click on it and go to "Open in browser window." Make sure that either your web browser allows pop-ups or that you know how to view the blocked pop-ups manually. In the new tab there will be a pop up prompt, click "Connect".
4.  In the command prompt that appears, type this: sudo su -
5.a.  You may want to create users (e.g., useradd jdoe; passwd jdoe).  You may want to set the password for the user (e.g., passwd initialuser # where "initialuser" is the user you first logged in as).
5.b. You may want to add the new user to the sudoers file. To do this, run this command:
usermod -aG sudo cooluser
6.  Modify the /etc/ssh/sshd_config file.  Make sure that the
"PasswordAuthentication" and "ChallengeResponseAuthentication" stanzas are uncommented out and set to yes.
6.b. If you want to see the history of the commands at the terminal with the "Up" arrow, please see this posting.
7.  Restart sshd.  One way would be to reboot. For a RedHat derivative enter this command as root /etc/init.d/ssh restart. Another way to restart sshd would be to use this: sudo service sshd restart
8.  Now you can use Putty to the external IP address of the Linux VM.  You should be able to log in with username/password combinations in step #5.

Leave a comment

Your email address will not be published. Required fields are marked *