Thursday, September 4, 2014

SHH key pair generation

How to generate an ssh key pair

let 's suppose that you want to generate an ssh key in order to connect to the machine called "enigma".

1. Generating the key

[root@enigma ~]# cd /root/.ssh
[root@enigma .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): enigma_key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in enig_key.
Your public key has been saved in enigma_key.pub.
The key fingerprint is: 91:c3:d9:ed:82:38:10:bc:28:d8:27:6b:04:ea:08:be root@enigma


Two files are created:
private key enigma_key, you can rename it to enigma_key.pem
public key: enigma_key.pub

2. Authorizing the generated key to connect to enigma

Append the content of enig_key.pub to /root/.ssh/authorized_keys
you can now use enigma_key.pem to connect to enigma from another machine.

Thursday, May 8, 2014

Emails sending with postfix using gmail account

Send an email with postfix using gmail account


1. Add the following information to /etc/postfix/sasl_passwd file

[smtp.gmail.com]:587    your_gmail_account@gmail.com:your_gmail_password

2. Create a new script you call something like sen.sh with the following content


receiver_mail_address=$1
subject=$2
content=$3

sendmail $receiver_mail_address <<EOF
subject:$subject
Content-Type: text/html #if you want to support html content
from:your_gmail_account@gmail.com
$content
EOF

You can now send email with the following command:

$sen.sh some_receivr@domain.com "test email" "this is a test"

Friday, April 4, 2014

Add/Rename a column to/in a table in Rails ActiveRecords

Let's consider that you already have a Users table

$ rails generate migration AddEmailToUsers

This will create the following file

db/migrate/some_timestamp_add_email_to_users.rb

Edit this file as the following

class AddEmailToUsers < ActiveRecord::Migration
  def change
    #to add a new column
    add_column :users, :email, :string
    # to rename an existing column
          rename_column :users, :username, :user_name
  end
end

And finally run

rake db:migrate


Check your database, a new column "email" was added to all users tables.