Linux and SSH for Noobs

 

Since starting grad school I have gained a whole new appreciation for linux. Ubuntu has been my primary OS since 8.04 (Hardy Heron) but I hadn't really looked much at how to really streamline and optimize my workflow until this year.

At my university, all Windows computers run an antivirus program that kills performance. It runs ruthlessly and suck up a lot of computer resources. This has only reinforced my choice to use linux as the IT guys will not provide any support and will not install anything on your computer, thus allowing complete freedom. Not all workplaces may allow for this but it does make things much easier if they do.

What is SSH?

SSH is a cryptographic network protocol that allows for secure network operations over a non-secured network. What this means is that users have the ability to securely login to remote systems on almost any network.

Why should I use it?

I have known about SSH for years but never used it extensively. It has only been this year that I started using it on a daily basis. My supervisor has a computer hidden in another building on campus that we use for backing up our software repositories (I also use GitLab for an extra layer of safety) and the easiest way to access it is with SSH. SSH allows for easy control over remote computers. I can simply login, backup my files, logout and then go on with my day.

My other main excuse for using SSH is that some FPGA software that I need to use (Xilinx's Vivado) is not compatible with my version of linux. With some tweaking I might be able to get it working, but I took the alternative choice and simply installed a compatible version of linux (CentOS 7) on one of the many lab computers not in my office. Now I am able to use SSH and X11 forwarding to control the GUI of Vivado from my main machine while all the heavy lifting is done on another computer. Distributed workloads is another wonderful feature that can be easily implemented in linux using SSH.

SSH Basics 

 

There are a lot of SSH commands but the basics are as follows:

Remote Terminal

This will allow you to login to a remote computer via a terminal.

ssh user@[IP address or computer name]

example:
ssh alex@test.comp.ca
ssh alex@192.168.0.105

Remote Terminal with Local GUIs

This will allow you to login to a remote computer via terminal and display GUIs from the other computer on your current machine. The '-X' will enable X11 forwarding. If that is not enabled on the host machine then no GUI will be displayed on your current machine.

ssh -X user@[IP address or computer name]

example:
ssh -X alex@test.comp.ca
ssh -X alex@192.168.0.105

Transferring Files To/From Remote Machine 

This command will allow you to quickly transfer files from your computer to another via ssh. The source and destination must be formatted as follows: [IP address or computer name]:/path/to/file. Remove the square brackets when plugging in the information and it should work.  

scp [source] [destination]

example:
scp /local/path/to/file.png alex@some.comp.uter.ca:/home/alex/Pictures/

SSH Keys

 

SSH keys are a fantastic way to make remote logins even easier than they already are. Instead of having to type in a password every single time you login or use an SSH command you can simply issue the command and be logged in automatically.

Generating Keys

This can be done by using ssh-keygen. This can be quickly done using the following:

ssh-keygen

This will then ask where the key should be saved, the password for the key (not using a password is less secure but more convenient). There are also a variety of other modifying commands that can be used but ssh-keygen will get the trick done for most users. The default command should be sufficient for most users.

Using Keys

In order to use the keys you need to copy your public key from the server (or computer you are looking to connect to via SSH) and store it on the computer you want to connect to.

This can be done using scp outlined above but...

DO NOT SHARE THE PRIVATE KEY! 

There are many ways that the files can be shared but it is likely the safest to use scp (uses SSH to transfer the public key) or ssh-copy-id. When using scp you have to do some additional configuration so if possible use ssh-copy-id.

example:
ssh-copy-id -i ~/.ssh/key_you_want_to_use user@host

Some distros will need additional changes to settings to allow for passwordless login (CentOS 7 needed me to do this). A quick google search will give you the details on what to do for your distro.

Any feedback? Leave it down below!  

 


















Comments

Popular posts from this blog

Ongoing Linux Cheatsheet

Baremetal Drivers: RFM69HCW and FRDM-K22F

Hindsight 20/20: University Productivity Tips and Tricks