Logging In Remotely

Virtually all Unix systems allow users to log in and run programs over a network from other locations. This feature is intrinsic to Unix systems, and only disabled on certain proprietary or embedded installations. It is possible to use both GUIs and CLIs in this fashion, although GUIs may not work well over slow connections such as a slower home Internet services. Different graphical programs have vastly different bandwidth demands. Some will work fine over a DSL, cable, or WiFi connection, while others require a fast wired connection.

The command line interface, on the other hand, works comfortably on even the slowest network connections.

Logging into a Unix CLI from a remote location is usually done using Secure Shell (SSH).

Caution

Older protocols such as rlogin, rsh, and telnet, should no longer be used due to their lack of security. These protocols transport passwords over the Internet in unencrypted form, so people who manage the gateway computers they pass through can easily read them.
Unix to Unix

If you want to remotely log in from one Unix system to another, you can simply use the ssh command from the command line. The general syntax of the ssh command is:

ssh [flags] login-id@hostname
            

The login-id portion is your login name on the remote host. If you are logging into a campus-managed server, this is likely the same campus login ID used to log into other services such as VPN, email, Canvas, etc.

The first time you connect to each remote host, you will be asked to verify that you trust it. You must enter the full word "yes" to continue:

The authenticity of host 'unixdev1.ceas.uwm.edu (129.89.25.223)' can't be established.
ED25519 key fingerprint is SHA256:askjdkj2ksjfdfamnmnmw5lka7jdkjka,mksjdkssfj.
No matching host key fingerprint found in DNS.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
            

If the connection is successful, you will be asked for your password. Note that nothing will echo to your screen as you type the password. Login panels that echo a '*' or a dot for each character are less secure, since someone looking over your shoulder can see exactly how long your password is. Knowing the length reduces the parameter space they would have to search in order to guess the password.

If you plan to run graphical programs on the remote Unix system, you may need to include the -X (enable X11 forwarding) or -Y (enable trusted X11 forwarding) flag in your ssh command. Run man ssh for full details.

Caution

Use -X or -Y only when connecting to trusted computers, i.e. those managed by you or someone you trust. These options allow the remote system to access your display, which can pose a security risk. For example, a hacker on the remote system could display a fake login panel on your screen in order to steal your login and password.

Caution

Only ssh should be used to log into remote systems. Older commands such as rsh and telnet lack encryption and are not secure. If anyone tells you to use rsh or telnet, they should not be trusted regarding any computing issues.

Examples:

shell-prompt: ssh joe@unixdev1.ceas.uwm.edu
            

Note

For licensing reasons, ssh may not be included in basic Linux installations, but it can be very easily added via the package management system of most Linux distributions.

If you have X11 capabilities and used -X or -Y with your ssh command, you can easily open additional terminals from the command-line if you know the name of the terminal emulator. Simply type the name of the terminal emulator, followed by an '&' to put it in the background. ( See the section called “Shell Features for Job Control” for a full explanation of background jobs. ) Some common terminal emulators are coreterminal, konsole, urxvt, and xterm.

shell-prompt: coreterminal &
            
Windows to Unix

If you're connecting to a Unix system from a Windows system, you will need to install some additional software.

Cygwin

The Cygwin Unix-compatibility system is free, quick and easy to install, and equips a Windows computer with most common Unix commands, including a Unix-style Terminal emulator. Once Cygwin is installed, you can open a Cygwin terminal on your Windows desktop and use the ssh command as shown above.

The Cygwin installation is very quick and easy and is described in the section called “Cygwin: Try This First”.

PuTTY

A more limited method for remotely accessing Unix systems is to install a stand-alone terminal emulator, such as PuTTY, https://www.chiark.greenend.org.uk/~sgtatham/putty/. PuTTY has a built-in ssh client, and a graphical dialog box for connecting to a remote machine. For more information, see the PuTTY documentation.

Terminal Types

In rare cases, you may be asked to specify a terminal type when you log in:

TERM=(unknown)
            

Terminal features such as cursor movement and color changes are triggered by sending special codes (characters or character combinations called magic sequences) to the terminal. Pressing keys on the terminal sends codes from the terminal to the computer.

Different types of terminals use different magic sequences. PuTTY and most other terminal emulators emulate an "xterm" terminal, so if asked, just type the string "xterm" (without the quotes).

If you fail to set the terminal type, some programs such as text editors will not function. They may garble the screen and fail to recognize special keys such as arrows, page-up, etc.

You can set the terminal type after logging in, but the methods for doing this vary according to which shell you use, so you may just want to log out and remember to set the terminal type when you log back in.

Example 3.3. Practice Break

Note

For this, and all practice breaks that follow, students should do the exercises shown. If you are reading this for a class, then these exercises are meant to be done in class. Try them on your own, do your best to understand what is happening, and ask the instructor for clarification if necessary.

Remotely log into another Unix system using the ssh command or PuTTY, or open a shell on your Mac or other Unix system. Then try the commands shown below.

Unix commands are below preceded by the shell prompt "shell-prompt: ". Other text refers to input to the program (command) currently running. You must exit that program before running another Unix command.

Lines beginning with '#' are comments to help you understand the text below, and not to be typed.

Don't worry if you're not clear on what these commands do. You do not need to memorize them right now. This exercise is only meant to help you understand the Unix CLI. Specific commands will be covered later.

# Print the current working directory
shell-prompt: pwd

# List files in the current working directory (folder)
shell-prompt: ls
shell-prompt: ls -al

# Two commands on the same line.  A ';' is the same as a newline in Unix.
shell-prompt: ls; ls /etc

# List files in the root directory
shell-prompt: ls /

# List commands in the /bin directory
shell-prompt: ls /bin

# Search the directory tree under /etc
shell-prompt: find /etc -name '*.conf'

# Create a subdirectory
shell-prompt: mkdir -p Data/IRC

# Change the current working directory to the new subdirectory
shell-prompt: cd Data/IRC

# Print the current working directory
shell-prompt: pwd

# See if the nano editor is installed
# nano is a simple text editor (like Notepad on Windows)
shell-prompt: which nano

    If this does not report "command not found", then do the following:

# Try the nano editor.  Nano is an add-on tool, not a standard tool on
# Unix systems.  Some systems will not have it installed.
shell-prompt: nano sample.txt

# Type the following text into the nano editor:

This is a text file called sample.txt.
I created it using the nano text editor on Unix.

# Then save the file (press Ctrl+o), and exit nano (press Ctrl+x).
# You should now be back at the Unix shell prompt.

# Try the "vi" editor
# vi is standard editor on all Unix system.  It is more complex than nano.
# It is good to know vi, since all Unix systems have it.
shell-prompt: vi sample.txt

    Type 'i' to go into insert mode
    Type in some text
    Type Esc to exit insert mode and go back to command mode
    Type :w to save
    Type :q to quit
    
    # "ZZ" is a shortcut for ":w:q"

shell-prompt: ls

# Echo (concatenate) the contents of the new file to the terminal
shell-prompt: cat sample.txt

# Count lines, words, and characters in the file
shell-prompt: wc sample.txt

# Change the current working directory to your home directory
shell-prompt: cd
shell-prompt: pwd

# Show your login name
shell-prompt: id -un

# Show the name of the Unix system running your shell process
shell-prompt: hostname

# Show operating system and hardware info
shell-prompt: uname -a

# Today's date
shell-prompt: date

# Display a simple calendar
shell-prompt: cal
shell-prompt: cal 2023
shell-prompt: cal nov 2018
shell-prompt: cal jan 3000

# CLI calculator with unlimited precision and many functions
shell-prompt: bc -l
scale=50
sqrt(2)
8^2
2^8
a=1
b=2
c=1
(-b+sqrt(b^2-4*a*c))/2*a
2*a
quit

# Show who is logged in and what they are running
shell-prompt: w
shell-prompt: finger

# How much disk space is used by the programs in /usr/local/bin?
shell-prompt: du -sh /usr/local/bin/

# Copy a file to the current working directory
shell-prompt: cp /etc/profile .
shell-prompt: ls

# View the copy
shell-prompt: cat profile

# View the original
shell-prompt: cat /etc/profile

# Remove the file
shell-prompt: rm profile
shell-prompt: ls

# Exit the shell (which logs you out from an ssh session)
# This can also be done by typing Ctrl+d, which is the ASCII/ISO
# character for EOT (end of transmission)
shell-prompt: exit
    

Practice

Note

Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
  1. What must be added to Unix to allow remote access?

  2. Can we run graphical programs on remote Unix systems? Elaborate.

  3. Does the CLI require a fast connection for remote operation?

  4. What command would you use to log into a remote system with host name "myserver.mydomain.edu" using the user name "joe", assuming you want to run a graphical X11 application?

  5. What should you do if someone advises you to use rsh or telnet?

  6. How can Windows users add an ssh command like the one used on Unix systems?

  7. What is the purpose of the TERM environment variable? What will happen if it is not set correctly?