Archive

Archive for September, 2015

Create user for ssh access to aws ec2 instance

September 28th, 2015 No comments

Creating a user in an amazon ec2 instance in my case ubuntu:

sudo adduser <new_user>
# Next step gives access level
sudo adduser <new_user> sudo 

Create the folder .ssh for the user just created:

cd /home/<new_user>
mkdir .ssh

On your local computer:

    • Generate a key using strong encription:
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -C "optional comment about key"
    • Then check that .ssh directory and the files have right permissions:
chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
    • Next, upload the public key to your server:
cat ~/.ssh/id_rsa.pub | ssh ubuntu@<public_ip> 'cat - >> ~/.ssh/authorized_keys'

In the remote server:

    • Copy the authorized_keys from the ubuntu user to the newly created .ssh folder of the new user.
cp ~/.ssh/authorized_keys /home/<new_user>/.ssh/
    • Change the owner of the folder and files to the user newly created:
sudo chown <new_user>:<new_user> /home/<new_user>/.ssh/
sudo chown <new_user>:<new_user> /home/<new_user>/.ssh/authorized_keys
    • Finally login as the user you just created and ensure that the .ssh folder and authorized_keys have the right permissions.
chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/

At this point you should be able to login using the default amazon key to both users. But in order to login from your computer with the key and the you just created, it is necessary to remove the id_rsa.pub from your local .ssh/ folder.
In the authorized_keys from the you would need to remove the first entry so the can not login using the amazon default initial key.

Categories: aws, ec2 Tags: , ,

ggplot for python calling kivy matplotlib backend

September 1st, 2015 No comments

Based on the grammar of graphics, ggplot is a library for plotting graphs in R. By doing some readings seems like ggplot is a very good choice to produce multi-layered graphs. I found a package for python which provides a ggplot structure wrapped into matplotlib instructions. I gave it a try by installing it from source https://github.com/yhat/ggplot and then, since the library is heavily depending on matplotlib I changed the backend by default to use kivy by placing these two lines on top of each example tested:


import matplotlib
matplotlib.use('module://kivy.garden.matplotlib.backend_kivy')

The main advantage in my case is the minimum set of instructions required for creating plots. Some resources can be found here http://blog.yhathq.com/posts/ggplot-for-python.html. I have not fully tested it but I am giving it a try.

smooth.py ggplot

Matplotlib backend kivy in Windows hands on

September 1st, 2015 7 comments

The backend implementations for matplotlib in kivy work just with kivy versions greater or equal than 1.9.1. It is required to install kivy in development mode following these steps: http://kivy.org/docs/installation/installation-windows.html#use-development-kivy. After step 10 you can additionally run


python setup.py install

The script kivy.bat creates an environment in which some python tools are ready to use, for instance pip. The next step is to download numpy and matplotlib from this binaries repositories: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy and http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib. Once downloaded install both using pip and then install kivy-garden and the matplotlib package for kivy.


pip install "numpy-1.10.0b1+mkl-cp27-none-win32.whl"
pip install "matplotlib-1.4.3-cp27-none-win32.whl"
pip install kivy-garden
garden install matplotlib

You can go now to the folder that by default garden packages are installed. In my case C:\Users\my_user\.kivy\garden\


cd garden.matplotlib/examples
python test_plt.py

And you should be able to see the matplotlib widget working on windows. Follow the steps from http://kivy.org/docs/installation/installation-windows.html#send-to-method to create a shortcut to execute your kivy apps.

Now you can go directly to the garden path using a file explorer, do right click on test_plt.py and send to kivy-2.7.bat which will start the application.

Categories: kivy, matplotlib Tags: , ,