FEEG6002 - Applied Programming 6 - Working Remotely on Linux Server Sam Sinayoko 2015-11-06 1 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 2 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 3 / 25
Learning outcomes After studying this lecture you should be able to: Connect to a remote linux server with SSH via PuTTY on Windows via the terminal on Linux / OSX Display remote graphical applications on your local screen via X forwarding Edit files on the linux server using nano or emacs Sending files on the linux server using Firefox text editors sending emails on the remote files 4 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 5 / 25
Introduction Why remote servers? Websites Supercomputers: Iridis 4, Hector, Archer. Cloud computing: pay for what you use (computing time, memory etc) work anywhere Amazon AWS, Microsoft Azure CD-Adapco: CFD software usable in the cloud Wakari.io: http://www.wakari.io Sage: http://cloud.sagemath.com Why Linux / Unix The most common OS on servers. Can do almost everything from the command line Easy to install new software on 6 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 7 / 25
Connecting to Linux server Linux / OS X terminal ssh -X LOGIN@feeg6002.soton.ac.uk 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 Use an SSH client such as PuTTY: http://www.putty.org/ 8 / 25
Connecting to Linux server Example hostname # display local host name ssh -X ss53g10@feeg6002.soton.ac.uk hostname landade # <- the local server hostname ss53g10@feeg6002.soton.ac.uk s password: Last login: Fri Nov 7 12:43:11 2014 from srv00470.soton.ac ----------------------------------------------------------- System: Red Hat Enterprise Linux Server release 6.5 (Santi Server: srv00470.soton.ac.uk Service: SES Teaching Server Status: Production Purpose: SES Teaching Server ----------------------------------------------------------- srv00470 # <- the remote server hostname 9 / 25
X server > ssh -X Start X server locally before running "ssh -X" "ssh -X" connects the remote server to the local X server. This allows to display remote GUI applications. You can try [login@feeg6002]$ xterm & [login@geeg6002]$ emacs & [login@feeg6002]$ firefox & The "&" is to run the program asynchronously (in the background) so you can keep using the terminal. 10 / 25
Job control Job control 1 If 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 See http://software-carpentry.org/v4/shell/job.html for more info on "job control". 11 / 25
Installing an X server on the local machine Installing an X server on the local machine Linux: nothing to do (the X server is always running) OS X: may need to download and install X-Quartz (free) http://xquartz.macosforge.org/trac Windows: Exceed (commercial): available on university computers. Xming (free): http://sourceforge.net/projects/xming/ Exceed must be started before running Putty. 12 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 13 / 25
University Computer Your filestore directory on the remote server (/home/login/filestore) contains a folder mydocuments in sync with your Windows "My Documents" folder. 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 You can also simply use the GUI Function > Save As and navigate to mydocuments. 14 / 25
Transfering files to Linux server The scp command Works like cp but can copy file to/from remote server securely. Copying file to home directory on remote server # copy file to remote home directory scp file.c LOGIN@feeg6002soton.ac.uk: *Don t forget the trailing colon ":"*. One can give the remote path to # copy file to remote home directory scp file.c LOGIN@feeg6002soton.ac.uk:/remote/path/ 15 / 25
Transfering files to Linux server GUI programs Use one of the many GUI programs for transfering files to remote server: Windows: WinSCP http://winscp.net/eng/index.php OS X: Finder, mucommander http://www.mucommander.com/ Linux: Krusader http://www.krusader.org/ Include your login and the address of the server: ssh.feeg6002.soton.ac.uk 16 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 17 / 25
Text editors Non-GUI text editors on server Nano http://www.nano-editor.org/ Run with nano ^X (exit) means Ctrl+X Vim http://www.vim.org/ Run with vim Modal editor: press "I" to start insert mode and "ESC" to get back to command mode. Command mode is for moving around: try h,j,k,l keys, ":help tutor" to start tutorial and ":q" to quit. Run non-gui Emacs with "emacs -nw" (combine with "Ctrl-Z" to suspend, and "fg 1" to use again) GUI text editors on server Emacs: http://www.gnu.org/software/emacs/ Run Emacs with emacs & (see intro in next few slides) 18 / 25
Emacs intro Basics Use the GUI and the menus to get started. In Emacs, "C-" means "Ctrl+" and "M-" means "Alt+". Emacs prints information and reads information in the mini-buffer at the bottom of the screen. Use "M-x COMMAND" to run a command if you know its name. Use TAB for completion. C-x C-f C-x C-s M-x compile M-x eshell M-x cua-mode open or create file save file compile file (type the command you need the first time run the code in eshell make Ctrl-C and Ctrl=V work like on windows 19 / 25
Emacs buffers Emacs can run multiple files and programs (like the emacs terminal eshell) simultaneously. 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 The window can also be split to display multiple buffers simultaneously C-x 2 C-x 3 C-x 1 Split buffer horizontally Split buffer vertically Maximize the buffer When doing so, one can switch to another window with C-x o C-x o Switch to other window 20 / 25
Getting help in Emacs In Emacs C-h t C-h r Start the Emacs tutorial Start the emacs manual Online Official website: http://www.gnu.org/software/emacs/ Getting help: http://www.emacswiki.org/ Blog: http://masteringemacs.org/ 21 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 22 / 25
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). 23 / 25
Outline Learning Outcomes Introduction Connecting to Linux server Transfering files to Linux server Text editors Sending emails on remote server Summary 24 / 25
Summary Start X Server on local machine if needed Use "ssh -X LOGIN@feeg6002.soton.ac.uk" to connect to remote server on the command line or with PuTTY on Windows Start coding with your prefered text editor on the server (Emacs, Nano, or Vi). 25 / 25