How to: Interact with remote Unix Systems
If you’re a software developer or sysadmin, chances are that you will not always be working with a local machine. That is where remote access comes in. I’ve had to pick up how to do this through trial and error; hopefully this post will pull together information from all the disparate sources and will help newbies like myself learn a little more quickly.
This post will go through all the tools you will need to interact with remote Unix based systems while using Windows or Mac OSX. Why am I focusing on interacting with Unix based systems? Many of the computers you will want to access remotely will be running a variant of Linux (servers come to mind). Besides, I guarantee you will be a more productive programmer / computer operator if you learn Unix command line tools. I will be covering Unix command line tools in much greater depth in a later post.
Beginner
If all you need is to grab files off of a remote Unix computer or dump some files to said machine, you can use a client application to help. If you’re on Windows, you will want a copy of WinSCP. This is a GUI version of the command line tool secure copy (scp), and allows you to drag and drop files between your local machine and the remote computer. For users uncomfortable with command line tools, this is the easiest way to add and grab files to remote machines. WinSCP has some bizarre UI choices (the selection of file nodes is unlike anywhere else in the Windows OS) but it can be useful. For MacOSX you can use Fugu; it does much the same thing.
Intermediate
When copying and pasting files is not enough, you will need to roll your sleeves up and learn a few more tools. First, you need to get used to the idea of giving up your GUI windowing environment and interacting with a keyboard
The terminal. Learn to love it
First, you will need to learn how to navigate a Unix directory tree, as you will not have the nice GUI environment you are used to.
Nick@Macintosh-2 ~/Desktop/TestDir$ tree . . |-- SubFolder1 | |-- SubSubFolder1 | `-- test.txt |-- SubFolder2 `-- test.txt 3 directories, 2 files
I’m not going to duplicate all the information that’s already on the Internet about using the command line. Here’s a few commands you’ll absolutely need to know.
Command |
Description |
cd | change directory |
ls | list files in directory |
cp | copy files |
mv | move files |
mkdir | make directories |
Once you are comfortable moving around your own directory structure using the command line, you’re ready to interact with a remote machine.
SSH
See the man page for the full syntax, but the basic way to use ssh is as follows:
ssh username@remotemachine
where remotemachine is either the name of the machine, if it’s on your local network and is mapped to an IP Address, or the IP address. You must have an account on that machine, and permission to log in. You will be prompted for a password if necessary. There are plenty of guides online for how to use SSH, here’s a good intro guide.
Type ‘logout’ when you are finished.
Advanced
If you’re on a Linux box, you’ve probably already got screen installed. If you’re on Windows running Cygwin, there’s a patch to add screen support. If you’re on Mac, you can use MacPorts (one of my essential pieces of Mac software) to install screen:
port install screen
Command
|
Description
|
screen
|
Launches the screen program; you might see information popup describing the program
|
screen -S name
|
Creates a new screen session instance named ‘name’
|
screen -r
|
If there’s only one saved screen session, resume it; else displays the list of screen sessions available
|
screen -r text
|
Resume the screen session whose name includes ‘text’; if it’s ambiguous it will tell you so and you need to be more specific
|
While screen is running
Command
|
Description
|
Ctrl-a ? | Display all the keyboard commands |
Ctrl-a “
|
List all the current windows in the screen session
|
Ctrl-a A
|
Rename the current window
|
Ctrl-a k | Kill the current window (pops up a Dialog question) |
Ctrl-a d | Disconnect from the screen session; you can resume it later with screen -r |
Ctrl-a c | Create a new window |
Ctrl-a p | Go to previous window |
Ctrl-a n | Go to next window |
Ctrl-a S | Split the window |
Ctrl-a Q | Quit splitting the windows (go back to one) |
Ctrl-a Tab | Jump between split windows |
Ctrl-a a | Invoke a literal ctrl-a (jump to first character of input) |
If you’re a Unix guru who’s used to navigating through text with Ctrl-a to jump to the start of a line, this last command is very useful (and I just found it while researching this post; it was driving me nuts previously). On Windows the Ctrl-a a shortcut is not necessary; you can hit Home to jump to the front of the line. On a Mac, however, the Home key pages up.
Conclusion
Being able to interact with machines that are not right in front of you is a crucial skill to have in the IT business. It can also be useful if you’re in school and need to retrieve a file that you saved on a machine somewhere and that you don’t feel like walking across campus to access locally. There are all sorts of uses for the tools I’ve introduced here; hopefully this piques your interest and causes you to read more about them.