0% found this document useful (0 votes)
19 views3 pages

Sshmakefile

Uploaded by

Deepthi Jayanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Sshmakefile

Uploaded by

Deepthi Jayanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
2128123, 11:57 AM Remote Compilation Using SSH and Make Issue 21 “Linux Gazette...making Linux just a little more fun!" Remote Compilation Using SSH and Make By John R. Daily, [email protected] Problem Occasionally I use my Linux machine at home to write code that I intend to compile on a remote machine, While maintaining open ¢tp and telnet connections to the remote machine to handle the transfer and compilation steps is a manageable solution, T decided to explore ssh and make to develop a more automated method, The benefits of my solution: ‘+ No need to remember which files have been modified. + Ability to use Emacs’ compilation capabilities to move to errors in the source. ‘+ As mentioned above, no need to use ftp and telnet, and hence no benefit to keep an open dialup connection when not compiling, + Automate, automate, automate, Laziness is a virtue. Overview of Solution My first step was to set up ssh and related tools in order to allow secure copying of files to my remote system. While seiting up a .rhosts file is a (barely) acceptable solution, my IP address and name is different each time I dial in, and it ‘would be rather awkward to change the remote system's .rhosts file each time I dialed in. ssh allows me to use a much more secure form of authentication to copy files and execute remote commands. Once I had ssh behaving properly, I used Emacs’ info facility to explore implicit rules in makefiles, and wrote a simple makefile to handle the file transfers and remote compilation. As an example of the intended effect, assume my remote machine is called "remote" (and my local machine "local"), and 've just modified a source file called daenon.c. I would like to execute the following commands in an automated fashion (note that scp is a secure copy command packaged with ssh, and that the -c option specifies compression, useful for dialup connections): scp ~C daemon.c jdaily@renote:~/source-dire: Ssh -C renote "ed source-directory && make’ Implementation First, I needed sshd running on the remote system to handle my secure connections. Fortunately, sshd was already running on the remote system in question, but according to the man pages, it can be run as any user, and is restricted to handling connections for that user (which should be quite sufficient for our needs). Then, I needed to install the ssh toolset on my local machine. Again, ideally these would be installed in a public binary directory such as /usr/ocal/bin, but any user can install them in his/her home directory. {also wanted a key which would allow me to authenticate myself between systems, and which would eliminate the need ‘to type my password each time I tried to run one of the ssh commands. For this, I just ran ssh-keygen, and made sure to not give a pass phrase, so that none would be needed to use my private key to establish the connection. [jdailyBiocal ~}$ ssh-keygen Initializing random number generator... Generating p: sevett (distance 186) Generating q: - : : ce Computing the keys Testing the keys Key generation complete. Enter file in which to save the key (/hone/jdaily/.ssh/identity): Enter passphrase: sett (distance 498) hitps:tinuxgazette-netiesue2 Isshmake. html 1 2128123, 11:57 AM Remote Compilation Using SSH and Make Issue 21 Enter the same passphrase again: Your identification has been saved in /hone/jdaily/.ssh/identity. Your public key is: 1024 35 718535638573954(. Your public key has beer } Gdaily@local Saved in /hone/Jdaily/.ssh/identity.pub Once I had a public key, | used sep to copy it to the remote machine. [jdailyatocal ~]$ scp -¢ ~/.ssh/identity.pub jdailygrenote:~/.ssh/key jdaily's password: Then I logged into the remote host and copied the key file into ~/.ssh/authorized_hosts. Ifthat file already existed, T would have appended the key file. Following all this, I could run ssh and scp without needing either a password or a pass phrase to connect to renote, Now I needed a makefile to automate my system. Ideally, the files on the remote machine would be checked to see if they were older than the files on my local machine, and if so, they would be copied over. To simplify matters, I decided to keep a record of the "last transferred date" for each file by touching a corresponding file each time I copied a source file over. As an example, when I transferred a newer copy of daenon.c over, [ touched daemon. ct in the same directory. Any transfer ofa .h file would be marked by the creation of a file with a .ht suffix. ‘After poking around the info file for make, [ came up with the following makefile. REXEC=ssh SSHFLAGS=-C # Compress data REVOTE=daily@renote:~/source-directory FILES=dabug.ht messages.nt client.ct daenon.ct queue.ct queve.ht Sant tah S(TRANSFER) $(SSHFLAGS) $< $(REWOTE) touch $8 Bact 1 he S(TRANSEER) $(SSHFLAGS) $< $(RENOTE) touch $8 all-done: $(FILES) S(REXEC) $(SSHFLAGS) remote “cd source-cirectory 8& make" touch all-dene This had one limitation in particular; I was unable to specify command-line arguments for make on the remote machine without writing them directly into the makefile on my local system. While this was fine for the current application, I decided to generalize it by creating a run-rake shell script, which would handle the remote execution of make after calling make on the local system. Here is my run-make shell seript: s1/bin/sh make echo ssh -C renote \"cd source-directory \8\& make $*\" ssh -C renote "ed source-directory && make $*" I then removed the line from my makefile which remotely ran make. Here's the output from a successful compilation sequence. cd ~/source-directory/ -/run-nake scp ~C debug.h jdaily@renote:~/source-directory touch debug-ht scp ~C messages.h jdaily@renote:~/source-directory touch messages.ht scp ~C client.c jdailyfrenote:~/source-directory touch client.ct scp ~C daemon.c jdailyfrenote:~/source-directory touch daenon.ct scp ~C queve.c jdaily@renote:~/source-directory hitps:tinuxgazette-netiesue2 Isshmake. html 28 2128123, 11:57 AM Remote Compilation Using SSH and Make Issue 21 touch queve.ct scp -C queve.h jdaily@renote:~/source-directory touch queue.ht ‘touch al-done ssh -C renote “cd source-directory 88 make Bcc -Wall -Wstrict- prototypes -Wmissing-prototypes -g -c queve.c Bcc -Wall -Wstrict-prototypes -Wnissing-prototypes -B -DPORT=3008 -o daenon daenon.c queue.o ~lsocket -Ithread gcc -Well -Wstrict- prototypes -hmissing-prototypes -g -DPORT=3020 -o client client.c -Isocket Compilation finished at Sat Aug 9 @1:22:19 Tools ssi is a secure replacement for such tools as rsh, rlogin, and rcp. It can be found at http://www.es.hut.fi/ssh. nnake is a standard Unix utility. GNU’s make comes with most, if not all, Linux distributions. Copyright © 1997, John R. Daily Published in Issue 21 ofthe Linux Gazette, September 1997 [Meee [ee] SI hitps:tinuxgazette-netiesue2 Isshmake. html 38

You might also like