Tuesday, December 22, 2020

Connect to Google Cloud VM with SSH on MAC

On MAC, terminal app can be used to connect to Google Cloud VM with the below steps:

1. open terminal console, and generate the key pair with your user name (for example, student), and save it to a particular folder when promoted

ssh-keygen -C student 

2. open Google Cloud console, and open VM instance, click the edit link, and Add a new SSH Key section. Open the public key file generated in last step, copy and past the content to the public key text box in Google Cloud Console. The user name should show on left side of the text box. Save the change.


3. From the mac terminal, interactively connect to Google Cloud VM instance with ssl, with the parameter of private keyfile (master) and username (student) and VM public ip address as below

ssh -i /Users/mpro2/Documents/master student@35.224.168.51

ssh mynode -t bash


to execute a single command run below

ssh -i /Users/mpro2/Documents/master student@35.224.168.51 ifconfig

ssh -i /Users/mpro2/Documents/master student@35.224.168.51 ip link



Note, by default, the ip address of VM in GCP will change each time when VM restarts.



Monday, December 14, 2020

Set environment variable for JAVA_HOME

1. .profile for mac user

with the new update for mac os, the default terminal has moved from bash to zsh, so if you previously use .profile to setup the environment and path for current user, then you will need to change the file name to .zprofile, as zsh will load .zprofile, instead of .profile when a new terminal starts.


2.Display environment variable in console or terminal window

on Windows

echo %JAVA_HOME%


on mac, 

echo $JAVA_HOME


3. set environment variable for a particular terminal or console 

on windows:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0

Do not include quotation marks. This will not affect the JAVA_HOME environment variable setting in control panel's environment settings.