Difference between revisions of "Tips and tricks cjc73"

From CAC Documentation wiki
Jump to navigation Jump to search
Line 38: Line 38:
 
== macOS client config ==
 
== macOS client config ==
  
I like to set up configuration files, aliases, and functions to make remote work more streamlined. Note, the <code>%</code> at the start of a line indicates that the rest of the text is a command to be entered in the command line (Terminal.app or iTerm). The <code>%</code> is not part of the command. The term "VM" means "the Red Cloud virtual machine instance" that you want to connect to. If you have multiple VMs you can make additional entries.   
+
You can set up configuration files, aliases, and functions to make remote work more streamlined. Note, the <code>%</code> at the start of a line indicates that the rest of the text is a command to be entered in the command line (Terminal.app or iTerm). The <code>%</code> is not part of the command. The term "VM" means "the Red Cloud virtual machine instance" that you want to connect to. If you have multiple VMs you can make additional entries.   
  
 
The examples in this section assume:
 
The examples in this section assume:
# your VM username is <code>netid42</code>
+
# your VM username is <code>netid42</code>
# your SSH/Cloud key-pair is in <code>~/.ssh/id_rsa4096</code>
+
# your SSH/Cloud key-pair is in <code>~/.ssh/id_rsa4096</code>
# your VM IP address is 128.84.YY.XXX  
+
# your VM IP address is 128.84.YY.XXX  
# Google Chrome is installed in your /Applications folder (for app mode, optional)
+
# Google Chrome is installed in your /Applications folder (for app mode, optional)
  
  
Line 62: Line 62:
 
Use <code>ctrl-X</code> to stop editing and follow the prompts to save the file.
 
Use <code>ctrl-X</code> to stop editing and follow the prompts to save the file.
  
Next add an alias to your shell profile. For recent versions of macOS, this is in a file called <code>~/.zshrc<code>. If you still have bash as your main shell, try <code>~/.bash_profile</code>.
+
Next, add an alias to your shell profile. For recent versions of macOS, this is in a file called <code>~/.zshrc<code>. If you still have bash as your main shell, try <code>~/.bash_profile</code>.
  
 
<pre>
 
<pre>
Line 68: Line 68:
 
</pre>
 
</pre>
  
Add entries like the following 3 lines, making the appropriate substitutions for netid42, IP address and key file. Replace "myVM" with any short name you would like to use as the alias name (no spaces or special characters).  
+
Add entries like the following 3 lines, making the appropriate substitutions for netid42, IP address and key file. Replace "myVM" with any short name you would like to use as the alias name (no spaces or special characters). If your VM address changes in the future, be sure to update these entries. 
  
 
<pre>
 
<pre>
alias myVM='ssh -i /Users/netid42/.ssh/id_rsa4096 netid42@128.84.10.222'
+
alias myVM='ssh netid42@128.84.10.222'
myVM_nb() { ssh -i /Users/netid42/.ssh/id_rsa4096 -N -L "$1":localhost:"$2" netid42@128.84.YY.XXX; }
+
myVM_nb() { ssh -N -L "$1":localhost:"$2" netid42@128.84.YY.XXX; }
 
</pre>
 
</pre>
  

Revision as of 12:04, 7 January 2022

Prevent accidental writes to mount point folders

Suppose you have a folder at /mnt/mountpoint that you would like to use as a mount point for a volume. Because the mount point is a valid path to a location on the boot volume, it is possible to write data to the mount point even when the volume is not mounted. Data written to the mount point will not be on the external volume --- it will be on the boot volume. It can a source of confusion, especially because copying data into the mount point and then later properly mounting a volume will hide any data on the boot drive that is in the mountpoint directory.

To avoid this, make the mountpoint directory unwritable so attempting to write data to the mountpoint when the volume is not mounted will generate an error.

  1. sudo chattr +i/mnt/mountpoint

Configure screen with .screenrc

Using a program like screen to keep your session active makes your computation robust to network interruption and disconnections. This means you can keep a process running on an instance even if your local machine is turned off or not connected to the internet.

Screen also has a number of optional features that make working from a remote terminal more pleasant. One feature is the "hard status" bar across the bottom the screen, which is roughly analogous to a tab bar. It will show the open screen windows as numbered "tabs" and the currently open window will be highlighted. A window can be renamed by entering the command sequence ctrl-a, shift-a. The new name will show in the tab bar.

You can enable the hard status bar (and extended scroll back history) by using nano to create a file called .screenrc in your home directory.

% nano ~/.screenrc

Copy and paste the following into the nano editor:

#termcapinfo xterm* ti@:te@
autodetach on # Autodetach session on hangup instead of terminating screen completely
startup_message off # Turn off the splash screen
defscrollback 30000 # Use a 30000-line scrollback buffer
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "

Use ctrl-X to stop editing and follow the prompts to save the file. The next time you launch screen, it will show the status bar along the bottom.


macOS client config

You can set up configuration files, aliases, and functions to make remote work more streamlined. Note, the % at the start of a line indicates that the rest of the text is a command to be entered in the command line (Terminal.app or iTerm). The % is not part of the command. The term "VM" means "the Red Cloud virtual machine instance" that you want to connect to. If you have multiple VMs you can make additional entries.

The examples in this section assume:

  1. your VM username is netid42
  2. your SSH/Cloud key-pair is in ~/.ssh/id_rsa4096
  3. your VM IP address is 128.84.YY.XXX
  4. Google Chrome is installed in your /Applications folder (for app mode, optional)


First edit or create ~/.ssh/config. In Terminal.app enter the following to open the ssh config file in the nano text editor. Use the arrow keys to move the cursor as needed.

% nano ~/.ssh/config

Once nano opens add an entry like the following:

Host 128.84.YY.XXX                   # your VM IP          
   User netid42                      # your user name on the VM  
   IdentityFile ~/.ssh/id_rsa4096    # the path to your ssh key file

Use ctrl-X to stop editing and follow the prompts to save the file.

Next, add an alias to your shell profile. For recent versions of macOS, this is in a file called ~/.zshrc. If you still have bash as your main shell, try ~/.bash_profile.

% nano ~/.ssh/config

Add entries like the following 3 lines, making the appropriate substitutions for netid42, IP address and key file. Replace "myVM" with any short name you would like to use as the alias name (no spaces or special characters). If your VM address changes in the future, be sure to update these entries.

alias myVM='ssh netid42@128.84.10.222'
myVM_nb() { ssh -N -L "$1":localhost:"$2" netid42@128.84.YY.XXX; }

Optionally, add this line to enable opening jupyter lab in Chrome's "app mode". It presents a less cluttered browser window. No changes are needed unless Chrome is not installed in the Applications folder.

lab_appp() { /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app="http://localhost:""$1""/?token=""$2"";"; }

Use ctrl-X to stop editing and follow the prompts to save the file.