Wednesday, February 25, 2009

When you need to ssh to server without entering password.

Loggin into server without password is stupid way. But sometime we need to do that e.g. Cron

So

# CREATE DSA AT CLIENT
user1@client:~$ ssh-keygen -t dsa

Generating public/private dsa key pair.
Enter file in which to save the key (/Users/user1/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/user1/.ssh/id_dsa.
Your public key has been saved in /Users/user1/.ssh/id_dsa.pub.
The key fingerprint is:
9a:30:11:3c:3c:cf:89:01:3a:e1:5d:bd:49:c9:50:f4 user1@client
The key's randomart image is:
+--[ DSA 1024]----+
|. .+.o*o. |
|.o. B. =. |
|o. ..B..oE |
| . ..+o |
| o S |
| o o |
| o |
| |
| |
+-----------------+

# COPY PUBLIC DSA TO SERVER

user1@client:~$ scp ~/.ssh/id_dsa.pub user1@some.server.com:/home/user1/.ssh

user1@some.server.com's password:
id_dsa.pub 100% 642 0.6KB/s 00:00


# SETUP AUTHORIZED_KEY FROM CLIENT TO SERVER
user1@some.server.com:~$ cd ~/.ssh
user1@some.server.com:~$ touch authorized_keys
user1@some.server.com:~$ chmod 600 authorized_keys
user1@some.server.com:~$ cat id_dsa.pub >> authorized_keys


DONE!

Sunday, February 22, 2009

PyCon

สิ่งหนึ่งที่ผมชอบบน Python คือ PyCon เพราะว่าเป็นการทำให้เกิด Community และวันนี้ก็เห็นอันนี้พอดี

Google App Engine: How to survive in Google's Ecosystem (#53)

Mr. Jodok Batlogg bio
30min ◊◊ Intermediate
Saturday 01:50pm, Ballroom II
categories: case study, django, gae, web, web services

It all started in 2003 with Plone, continued in 2005 with Zope3 and right now the road seems to go to the Cloud, namely Google App Engine.

In this talk the experiences building a community portal based on Google App Engine will be presented. The main parts are: the App Engine Python SDK, Google's Bigtable, the Admin AJAX interface based on Google Web Toolkit / ext GWT, the delivery frontend using Django, Amazon Webservices handling large files and Content Delivery and of course as mentioned beforehand business aspects.




ต้องลองไปสักครั้ง ว่ามั๋ย

Wednesday, February 11, 2009

Secure TCP/IP Connections with SSH Tunnels กับ PostgreSQL

ผมชอบ SSH ตรงที่มันสามารถทำ SSH Tunnels ได้นี่แหละ และก็อีกครั้งที่ผมได้ประสบการณ์ดี ๆ เกี่ยวกับการใช้งาน Database ระยะไกลอีกครั้ง

|---------------------|
| 222.222.22.222 |
| Postgres:5432 |
|----------|----------|
|
|
|---------------------|
| 10.0.0.01 |
| Firewall |
|----------|----------|
|
|
|---------------------|
| 10.0.0.20 |
| local web server |
|----------|----------|


ดูจากรูป เครื่อง Server ของผมฝากไว้ที่ ISP โดยได้ทำการ ติดตั้ง PostgreSQL และ run ไว้ที่พอร์ต 127.0.0.1:5432 เพราะว่าไม่อยากให้ใครมาต่อ นอกจากที่ตัวมันเอง

คราวนี้ก็เป็นประเด็นว่า แล้วถ้าอยากต่อ Database ไปยังเครื่อง Server จากที่อยู่หลัง FireWall หละ จะทำอย่างไร อย่างแรกที่นึกออกก็คือ VPN

หลังจากติดตั้ง OpenVPN แล้ว ปัญหาก็ตามมา คือ มันช้า แล้วก็หลุดบ่อยด้วย หาทางแก้อยู่ตั้งนาน สุดท้ายก็มาจบที่ SSH Tunnel อีกตามเคย


เอกสารที่ผมนำมาเล่าให้ฟังนั้นสามารถอ่านแบบภาษาอังกฤษได้ที่ http://developer.postgresql.org/pgdocs/postgres/ssh-tunnels.html


ขั้นแรกก็ SSh เข้าไปที่เครื่อง local ก่อน
$ ssh username@10.0.0.20

ต่อมาก็ต้องลุยด้วยการสร้าง Tunnel
$ ssh -L 63333:localhost:5432 username@222.222.222.222
# อธิบายได้ดังนี้
# จะทำการสร้าง Tunnel ที่ 10.0.0.20:63333 (เค้าเรียกว่า End of Tunnel) ไปยัง 222.222.222.222:5432 (เรียกว่า End of Remote Tunnel) และก็เป็นพอร์ตที่เปิดให้บริการ Database อยู่ด้วย
# โดยใช้ผู้ใช้งาน username ต่อไปยัง 222.222.222.222

ที่เครื่อง local web server ตรวจดูความเรียบร้อยหน่อยว่า มีการเปิดพอร์ต 63333 ไว้จริงหรือไม่ด้วย
$ netstat -an |grep 63333

จากนั้นก็ลองดูว่าสามารถใช้งาน postgres ได้จากเครื่อง local หรือไม่
$ psql -h localhost -p 63333 -U postgresuser -l


แล้วคุณจะพบกับความมหัศจรรย์

Sunday, February 1, 2009

Finish, Done, Ready ในความหมายของฝรั่ง

อันนี้ดองไว้นาน...

คุณมีความคิดเห็นอย่างไรกับคำว่า Finished, Done และ Ready
เวลาใช้งานนั้นต้องดูว่าใช้งานกับใคร ถ้าเป็นคนไทยคำ 3 คำนั้นดูแล้วมีความหมายเหมือนกันคือเสร็จซักที แต่หากนำไปใช้กับฝรั่ง หรือคนที่ยึดมั่นในความหมายของมันแล้วนั้นคุณอาจใช้ผิดก็ได้

คำว่า Finish, Done และ Ready นั้น ในทางปฏิบัติกับฝรั่งนั้นจะมีความหมายว่า เสร็จสิ้น ไม่มีอะไรทำต่อแล้ว ถ้าหากต้องมีการทำต่อคือสิ่งที่เพิ่มเติมภายหลัง แต่บ่อยครั้งที่ผมพลาดไป คือ เสร็จแล้ว แต่ว่าขอแก้ไขตรงนี่นิด ตรงนั้นหน่อย จึงไม่แปลกว่าฝรั่งเค้าจะเคืองได้

ตั่งแต่นั้นเป็นต้นมาผมจึงใช้คำว่า Finish, Done และ Ready น้อย ๆ และเมื่อมันถึงเวลาแล้วเท่านั้น