1 Command For SSHing Into A CSIF Machine

Transcription

Setting up my Dev Environment1ECS 030Command for SSHing into a CSIF MachineIf you already have a terminal and already have a working ssh program (That is, youtype ssh into the terminal and it doesn’t say it cannot recognize the command), simplytype in the following:ssh username@pcxx.cs.ucdavis.eduReplace username by your CAS Kerberos username and xx by a two-digit number(I checked 10 and 12 and they worked, but you can choose any between 1-60). Oncesuccessful, the terminal would prompt you to input your password. Type in your Kerberospassword for CAS and you should be able to login.For logging out the ssh session, type “logout” or “exit”.2How to Install SSH2.1Windows1. Go to https://www.cygwin.com and download the setup.exe. Make sure that youmake the right choice for 32/64-bit.Remark. Briefly speaking, cygwin is something that emulates a Unix-like environment on Windows. It includes, among a lot of other things, a terminal programwhere you can execute Unix commands like cd, ls, etc.2. Double click the setup.exe and begin the installation. Choose the following optionsduring the process:(a) Choose “Install from Internet” at “Choose A Download Source” page.(b) Choose a root directory yourself. This will be the place which the going-tobe installed cygwin bash treats as its own root. For example, if you specify“C:\cygwin64” as your root directory, “/home/james” will in fact be locatedin “C:\cygwin64\home\james”.(c) Choose “All Users” (the other option should also work, even though I haven’ttested it.).(d) Choose a local package direcotry. This is the place cygwin stores all the filesthat are necessary for emulating the unix environment.(e) Select “Direct Connection”.(f) Select an available download site from the provided list. Any of them shouldwork. I simply chose the very first one: http://cygwin.mirror.constant.com(g) The installer will grab some package listing info from the site you chose, andthen open a package setup window. This window allows you to specify whichpackages to install.1

(h) Under “Net” category, find the “openssh” package and click the “Skip” fieldof it. Make sure it changes to a version number and the checkbox of the“Bin?” column is checked. Basically, you need to install this ssh implementation, so that you can execute the ssh command once the installation completes.(i) Leave everything else unchanged (that is, the default option). Click Next button.(j) Wait until the installation finishes. I experienced an error message of “incomplete download” the first time, but a second trial succeeded.3. After installation of cygwin completes, find the “Cygwin64 Terminal” program andopen it (it should appear in the start menu if you told the installer to “include anicon in the start menu”). Now you can pretty much treat this terminal as a Unix oneand since you already installed openssh, you can ssh into a CSIF machine directly.Another option to connect to CSIF is the use of PuTTy. This application is a dedicatedSSH client. The installation steps and usage is very simple.1. Go to http://www.chirak.greenend.org.uk/ sgtatham/putty/download.html and download putty.exe file according to your installation.2. Launch PuTTy by double clicking on the downloaded file.3. In the Host Name (or IP address) box, type pcxx.cs.ucdavis.edu. Replace xx by atwo-digit number from 1 to 60.4. A security alert should appear the first time you connect to any given box. Thiswarning is just to inform you about the rsa2 key fingerprint of the machine. Youcan safely click “Yes”.5. The terminal should ask you for a login user. Use you Kerberos user and password.2

2.2MAC OS XMAC OS X should include a built-in SSH client that you can use directly in the Terminal.Simply type “ssh” to see what happens. It might prompt you to install other developertools. In that case, just follow the instructions.2.3Ubuntu (Other Debain-based System)To install ssh. Open a terminal and type the command:sudo apt-get install sshThe above command uses apt-get, the package manager on Debian-based linux systems to automatically download and install ssh. For linux distributions that’s not Debianbased, google and check the corresponding documentation to find out what package manager they use and use them to install ssh.3Developing locallyIf for some reason you can not have access to the CSIF machines, you can still work onyour homeworks locally in your computers. Although before submission we request thatyou test it in a CSIF machine, because we can not guarantee that what ever you have inyour environment is applicable for CSIF. And given we will grade in the later, it is yourresponsibility to guarantee it will compile and run in CSIF machines.3.1WindowsWindows systems provide a C compiler that can be downloaded when installing VisualStudio; an Integrated Development Environment. Although VS is a very nice tool, itregularly introduces a lot of special files and characters that makes development in Cvery complicated when doing cross platform development. Therefore we do not suggestyou use this tool.Nevertheless if you decided to install Cygwin, you are in great standing! Given thatCygwin is a Unix emulator, it also allows you to install a C/C compiler as another ofthe options in the installation process. You just have to select the gcc-core and gcc-g packages under devel.3

3.2MAC OS XMac machines already have a C/C compiler. Unfortunately it is not the same as theone used in CSIF. While CSIF uses GCC compiler, Mac has clang installed. This willnot cause a lot of issues for the initial part of the course, given that the code is prettygeneric. But as we move forward into more advanced topics this could become an issue.Therefore the recommendation for this cases is that once you think you are done withyour code in your machine, test it in a CSIF machine via SSH as described above.3.3Ubuntu (Other Debain-based System)Linux machines also already have a C/C compiler, the only thing you have to beaware is the version. But that should not be an issue. If for some reason your terminaldoes not finds the gcc command, you can install it using the following commands.sudo apt-get updatesudo apt-get install gcc-5 g -53.4CompilingTo compile your code remember that you have to be in the folder locaton where yoursource code is located. You should get there through the “cd” command. Once there youcan call the compilation commandgcc mycode.c -o mycodeThis command will compile “mycode.c” file and create the mycode executable. If youommit the -o option the executable will be named a.out. To execute the file just call itas follows./mycode4Text EditorThe selection of a text editor is crucial so you are not facing weird unforseen errors downthe road. You should choose the most basic ones in order to avoid the insertion of hiddencharacters in the executable code that could cause problems at compilation time. Hereare a list of some editors you can check and choose from the one you feel most comfortablewith. Notepad (Win) - A simple out of the box solution that is already installed in Windows machines. Notepad (Win) - A free source code editor that provides some higlighting functionalities for syntax and some tools for transfering your files from your local machineto a CSIF box. Simple, clean and FREE! Sublime (All platforms) - One of the best development tools you could ever get! It isa very mature text editor that provides tons of tools that eases the development andsharing of your code. Provides support for multiple languages for syntax checkingas well as customization options. But with great power comes great. cost; this isnot a free tool, but definitively is worth every penny.4

Atom.io (All platforms) - An open source version of Sublime developed by GitHub.Just as Sublime this tool grants you great tools and support for multiple languagesand customizations and is FREE! But as such, it does present some bugs. Nevertheless it is supported by one of the most dynamic communities of open source, soif you report any issue, chances are that they will be solved in a reasonable amountof time.If you decide to work directly on the CSIF machines via SSH, you also have some optionsavailable. These are the vi editor, nano and emacs. These are console based Text Editors.If you decide to use any of these, you can google their usage, because it is not as simpleas any of the others. Having said that, being able to use any of these editors tells a lotabout your programming skills.5Transfering files to CSIFOnce you are done developing and compiling your code in your machine, you should testit in the CSIF machines. To do so you must first be able to send your source code toCSIF boxes. To do so, there are two commands you can try sftp or scp.5.1sftpThis is the Secure FTP command that allows a safe connection between your machine anda CSIF box to transfer files. To connect to any given box you have to run the commandsftp username @pc##.cs.ucdavis.eduRemember to substitute username for your user name and ## with a numberbetween 1 and 60.This command will open the ftp console that allows you to put files into the location thatyou connect or get files from the remote location to your local machine.It is important to notice 2 things: The location where the files will be taken in order to be able to “put” them in theremote machine is the working directory where you call the sftp command. Forexample: Assume I have a file sample.txt at \home\user\mydocs, and a file namedmycode.c at \home\user\code. If I placed myself into mydocs folder, I would notbe able to get the mycode.c file to put it into the server. In the sftp prompt you can also use all the filesystem navigation commands thatwill allow you to navigate to any given folder in the remote machine in order topull it to your local machine. This also applies for the placing of files from my localmachine.To exit the client you just have to type the command “exit” and the sftp client will beclosed.5.2scpThis is the Secure copy command. This tool allows you to send files to a remote location,but does not allows you to get files from there. This is a great way to send your codefrom your local machine to the remote CSIF boxes. To use it, you call it as follows5

scp [list of files] username @pc##.cs.ucdavis.edu: remote destination path Remember to substitute username for your user name and ## with a number between 1 and 60. The list of f iles can be any number of filenames placed inthe relative location to the working directory where the command is executed. Theremote destination path should be the place where you want to put the files you aresending.5.3Visual interfacesFor Windows users there are two tools that could help with this task. These are Filezillaand WinSCP. Both tools are just front ends for both SFTP and SCP commands thatallow you to do drag and drop between both machines and avoids you to have to rewritethe commands multiple times with slight variations. The setup for either is pretty simpleand is available in ther download sites.6Final RemarkThe best way to learn how to configure and develop stuff is always to try them out andgoogle them. Therefore, if you experience some difficulties you should always think aboutwhat exactly your operation has done and googled accordingly, instead of directly askingsome seniors for help (Do not understand what “sudo” means in the above? Googlethat!). Believe it or not, no programmers can live without google and stackoverflow!6

CSIF boxes. To do so, there are two commands you can try sftp or scp. 5.1 sftp This is the Secure FTP command that allows a safe connection between your machine and a CSIF box to transfer les. To connect to any given box you have to run the command sftp username @pc##.cs.ucdavis.edu