Using RSA keys to auto copy files to server after build
Posted: Mon Jun 23, 2014 4:22 pm
To automatically copy files to a server after building an app, you can use RSA key pairs. Here are the steps I took on my MacBook (with the terminal app) to set things up on a Linux server...
I've included the output of the commands for reference.
To create a new RSA key pair, use the ssh-keygen command. You'll be asked for the file name to store the keys and for a passphrase. Instead of the default file 'id_rsa', I've specified 'MyKey_rsa' for the name of my key files. I left the password blank, so I can copy to the server without having to enter a passphrase each time.
ssh-keygen -t rsa
You can now copy the public key to the server using
cat ~/.ssh/MyKey_rsa.pub | ssh username@servername.com "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"This ensures that the .ssh folder exists on the server and appends the new public key to the file containing authorized keys.
To check it's all working, try copying a file to the server using your new private key - you shouldn't have to enter a passphrase
scp -i ~/.ssh/MyKey_rsa TestFile.pdf username@servername.com:
Now, you can use the scp (secure copy) command to transfer iOS / android files to the server after building. In the 'Copy command' text box in iOS options / android options, type the following...MobGUI will replace [FILES] with the actual files generated and they will be copied to the 'appFolder' folder as specified above.
For more info on the other iOS options, and for FTP / DropBox examples, check out http://forums.livecode.com/viewtopic.php?f=54&t=20747
To automatically use your new private key, you can edit (or create) a config file in the .ssh folder of your home folder.
vi ~/.ssh/configNow the default key will be used if you don't specify one on the command line...
If you set up the default key file the you don't need to specify the key file in the scp command in the 'Copy command' text box in iOS options / android options;As before, MobGUI will replace [FILES] with the actual files generated.
I've included the output of the commands for reference.
To create a new RSA key pair, use the ssh-keygen command. You'll be asked for the file name to store the keys and for a passphrase. Instead of the default file 'id_rsa', I've specified 'MyKey_rsa' for the name of my key files. I left the password blank, so I can copy to the server without having to enter a passphrase each time.
ssh-keygen -t rsa
Code: Select all
Zanzibar:Desktop splash21$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/splash21/.ssh/id_rsa): /Users/splash21/.ssh/MyKey_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/splash21/.ssh/MyKey_rsa.
Your public key has been saved in /Users/splash21/.ssh/MyKey_rsa.pub.
The key fingerprint is:
1f:3e:18:44:ed:39:30:fb:8a:4d:42:d9:dd:a2:ae:3c splash21@Zanzibar.local
The key's randomart image is:
+--[ RSA 2048]----+
| .. |
| .o . |
| o.* o |
| o.o * . |
| . So.o |
| . o=.. |
| *..+ |
| .E + . |
| oo |
+-----------------+
You can now copy the public key to the server using
cat ~/.ssh/MyKey_rsa.pub | ssh username@servername.com "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Code: Select all
Zanzibar:Desktop splash21$ cat ~/.ssh/MyKey_rsa.pub | ssh username@servername.com "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
username@servername.com's password:
Zanzibar:Desktop splash21$
To check it's all working, try copying a file to the server using your new private key - you shouldn't have to enter a passphrase
scp -i ~/.ssh/MyKey_rsa TestFile.pdf username@servername.com:
Code: Select all
Zanzibar:Desktop splash21$ scp -i ~/.ssh/MyKey_rsa TestFile.pdf username@servername.com:
TestFile.pdf 100% 108KB 108.5KB/s 00:00
Zanzibar:Desktop splash21$
Now, you can use the scp (secure copy) command to transfer iOS / android files to the server after building. In the 'Copy command' text box in iOS options / android options, type the following...
Code: Select all
scp -i ~/.ssh/MyKey_rsa [FILES] username@servername.com:appFolder/
For more info on the other iOS options, and for FTP / DropBox examples, check out http://forums.livecode.com/viewtopic.php?f=54&t=20747
To automatically use your new private key, you can edit (or create) a config file in the .ssh folder of your home folder.
vi ~/.ssh/config
Code: Select all
IdentityFile ~/.ssh/MyKey_rsa
If you set up the default key file the you don't need to specify the key file in the scp command in the 'Copy command' text box in iOS options / android options;
Code: Select all
scp [FILES] username@servername.com:appFolder/