FEEG6002 - Applied Programming 6 - Working
Remotely on Linux Server
Sam Sinayoko
2015-11-06
Outline
Learning Outcomes
Introduction
Connecting to Linux server
Transfering files to Linux server
Text editors
Sending emails on remote server
Outline
Learning Outcomes
Introduction
Connecting to Linux server Transfering files to Linux server Text editors
Sending emails on remote server Summary
Learning outcomes
After studying this lecture you should be able to: I Connect to a remote linux server with SSH
I via PuTTY on Windows
I via the terminal on Linux / OSX
I Display remote graphical applications on your local screen via X forwarding
I Edit files on the linux server using nano or emacs I Sending files on the linux server using Firefox
I text editors
Outline
Learning Outcomes
Introduction
Connecting to Linux server Transfering files to Linux server Text editors
Sending emails on remote server Summary
Introduction
Why remote servers?
I Websites
I Supercomputers: Iridis 4, Hector, Archer. I Cloud computing:
I pay for what you use (computing time, memory etc)
I work anywhere
I Amazon AWS, Microsoft Azure
I CD-Adapco: CFD software usable in the cloud
I Wakari.io: http://www.wakari.io
I Sage: http://cloud.sagemath.com
Why Linux / Unix
I The most common OS on servers.
Outline
Learning Outcomes Introduction
Connecting to Linux server
Transfering files to Linux server Text editors
Sending emails on remote server Summary
Connecting to Linux server
Linux / OS X terminal
ssh -X [email protected]
where LOGIN is your username on the server. You can only connect to a server where you have an account, and ssh will ask for your password.
The -X option forwards graphical applications to the local display. See slide XX.
Windows
Connecting to Linux server
Examplehostname # display local host name
ssh -X [email protected] hostname
landade # <- the local server hostname [email protected]’s password:
Last login: Fri Nov 7 12:43:11 2014 from srv00470.soton.ac.uk
---System: Red Hat Enterprise Linux Server release 6.5 (Santiago)
Server: srv00470.soton.ac.uk Service: SES Teaching Server Status: Production
Purpose: SES Teaching Server
---srv00470 # <- the remote server hostname
X server
> ssh -X
I Start X server locally before running "ssh -X"
I "ssh -X" connects the remote server to the local X server. I This allows to display remote GUI applications. You can try
I [login@feeg6002]$ xterm &
I [login@geeg6002]$ emacs &
I [login@feeg6002]$ firefox &
Job control
Job control1If you forget the "&", you can do "Ctrl-Z" to suspend the program. This will display a job number on the screen (say, [1]) and freeze the app, but it will free the terminal. To de-freeze the application, run
bg 1
to put it in the background. If you run
fg 1
you will put the application back in the foreground. The bg and fg commands are especially useful when using non-graphical programs in the terminal such as nano or emacs. These programs take over the shell but can be put in the
background temporarily with "Ctrl-Z" to bring back the shell, and later brought back a little later with fg. This avoids having to quit and restart commands constantly.
1
Seehttp://software-carpentry.org/v4/shell/job.htmlfor more
Installing an X server on the local machine
Installing an X server on the local machine
I Linux: nothing to do (the X server is always running) I OS X: may need to download and install X-Quartz (free)
http://xquartz.macosforge.org/trac
I Windows:
I Exceed (commercial): available on university computers.
I Xming (free): http://sourceforge.net/projects/xming/
Outline
Learning Outcomes Introduction
Connecting to Linux server
Transfering files to Linux server
Text editors
Sending emails on remote server Summary
University Computer
I Your filestore directory on the remote server
(/home/LOGIN/filestore) contains a folder mydocuments in sync with your Windows "My Documents" folder.
I You can put files in that folder to make them visible on Windows
emacs program.c
# (edit the program and save)
mv file.c /home/LOGIN/filestore/mydocuments
Transfering files to Linux server
The scp command
Works like cp but can copy file to/from remote server securely. I Copying file to home directory on remote server
# copy file to remote home directory
scp file.c [email protected]: *Don’t forget the trailing colon ":"*.
I One can give the remote path to
# copy file to remote home directory
scp file.c [email protected]:/remote/path/
Transfering files to Linux server
GUI programs
I Use one of the many GUI programs for transfering files to remote server:
I Windows: WinSCPhttp://winscp.net/eng/index.php
I OS X: Finder, muCommander
http://www.mucommander.com/
I Linux: Krusaderhttp://www.krusader.org/
Outline
Learning Outcomes Introduction
Connecting to Linux server Transfering files to Linux server
Text editors
Sending emails on remote server Summary
Text editors
Non-GUI text editors on server
I Nanohttp://www.nano-editor.org/
I Run with nano
I ^X (exit) means Ctrl+X
I Vim http://www.vim.org/
I Run with vim
I Modal editor: press "I" to start insert mode and "ESC" to get
back to command mode.
I Command mode is for moving around: try h,j,k,l keys, ":help
tutor" to start tutorial and ":q" to quit.
I Run non-GUI Emacs with "emacs -nw" (combine with "Ctrl-Z" to suspend, and "fg 1" to use again) GUI text editors on server
I Emacs: http://www.gnu.org/software/emacs/
Emacs intro
BasicsI Use the GUI and the menus to get started.
I In Emacs, "C-" means "Ctrl+" and "M-" means "Alt+". I Emacs prints information and reads information in the
mini-buffer at the bottom of the screen.
I Use "M-x COMMAND" to run a command if you know its name. Use TAB for completion.
C-x C-f open or create file C-x C-s save file
M-x compile compile file (type the command you need the first time). M-x eshell run the code in eshell
M-x cua-mode make Ctrl-C and Ctrl=V work like on windows
Emacs buffers
I Emacs can run multiple files and programs (like the emacs terminal eshell) simultaneously.
I Each file or program is displayed in its own buffer. Switch buffer with C-x b:
C-x b display a different buffer in current window I The window can also be split to display multiple buffers
simultaneously
C-x 2 Split buffer horizontally C-x 3 Split buffer vertically C-x 1 Maximize the buffer
Getting help in Emacs
In Emacs
C-h t Start the Emacs tutorial C-h r Start the emacs manual
Online
I Official website: http://www.gnu.org/software/emacs/
I Getting help: http://www.emacswiki.org/
I Blog: http://masteringemacs.org/
Outline
Learning Outcomes Introduction
Connecting to Linux server Transfering files to Linux server Text editors
Sending emails on remote server
Sending emails on remote server
firefox
Run Firefox on remote remote server with command firefox &
and use Outlook Web Access to write and attach email
Note: Sometimes firefox detects if it is already running on the local computer, and switches to that application instead of starting a remote one. If that happens Close your local copy of firefox and try again (or run firefox locally with the -no-remote option).
Outline
Learning Outcomes Introduction
Connecting to Linux server Transfering files to Linux server Text editors
Sending emails on remote server
Summary
I Start X Server on local machine if needed
I Use "ssh -X [email protected]" to connect to remote server on the command line
I or with PuTTY on Windows
I Start coding with your prefered text editor on the server (Emacs , Nano, or Vi).