Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, October 21, 2011

Setting up more Django on a clean Ubuntu server

Get virtualenvs and virtualenvwrapper following this and this and this (with an informative video)

On root account:
1. sudo apt-get install python-setuptools

2. sudo easy_install virtualenv

3.
virtualenv ve_msw
New python executable in ve_msw/bin/python
Installing setuptools............done.
Installing pip...............done.

4. easy_install pip (I could also have done "pip install virtualenv" or "easy_install virtualenvwrapper"

5. pip install virtualenvwrapper

On user account:
6. mkdir ~/.virtualenvs

7. Add to end of ~/.bashrc:
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

8.
$ mkvirtualenv ve_msw
New python executable in ve_msw/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/haoqili/.virtualenvs/ve_msw/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/haoqili/.virtualenvs/ve_msw/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/haoqili/.virtualenvs/ve_msw/bin/preactivate
virtualenvwrapper.user_scripts creating /home/haoqili/.virtualenvs/ve_msw/bin/postactivate
virtualenvwrapper.user_scripts creating /home/haoqili/.virtualenvs/ve_msw/bin/get_env_details

9. Added to ~/.virtualenvs/postmkvirtualenv
proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
mkdir $HOME/Projects/$proj_name
add2virtualenv $HOME/Projects/$proj_name
cd $HOME/Projects/$proj_name
easy_install readline ipython
pip install -e git://github.com/jbalogh/check.git#egg=check Jinja2==2.3.1 \
    MySQL-python==1.2.3c1 lxml==2.2.6 PIL

10. Now I can call workon ve_msw

MSW already have playdoh set up at the very beginning
11. To set up where virtualenvwrapper's "workon" takes us to add this to
~/.virtualenvs/ve_msw/bin/postactivate
cd ~/path/to/mswdir

Thursday, October 20, 2011

Linux add user

adduser username
not useradd username

Story: 

######## Stage 1. Stuck & Confused ############

I'm was trying to set up my Rackspace server and I ran into some questions during my created user account.

From root, I added a user with "useradd alice". When I discovered that ~/ failed, I had to sudo mkdir /home/alice.

Q0: It's so strange that the user home dir has to be manually created

Then I logged in as alice, but found that the prompt is not customized and lacks color. Since useradd copied /etc/skel/.bashrc from root to alice, I thought that I can just "cp /etc/skel/.bashrc ~/.bashrc", but when I did that (with sudo), "echo $PS1" still shows the old original prompt settings.

Q1: How come the ~/.bashrc, identical in root and user alice, does not work in alice?

I even uncommented out "force_color_prompt=yes", but its still not working.

Q2: How come user alice needs sudo to edit ~/.bashrc in the first place when its permissions are (from ls -l):
        alice@simba:~$ ls -l ~/.bashrc
        -rw-r--r-- 1 root root 141 2011-10-20 05:19 /home/alice/.bashrc

Answer: Because the user and group of /home/alice/.bashrc are both set to "root" (The user is the one that matters here)

Then I tried to "sudo chown alice:alice ~/.bashrc", but was denied permission because I was on alice.


######### Stage 2. Found good resource ############

Then I read this informative article and learned:

useradd -D shows the defaults of useradd. You can change the shell to bash by specifying useradd -D -s /bin/bash . Then you can use useradd alice followed by passwd alice to set its password.  BUT!! This still doesn't automatically make /home/alice for you


######## Stage 3. Problems solved! ################

adduser alice worked beautifully
0: home dir created automatically :D
1: bashrc and xterm-color both work :D
2: home dir's files are automatically made with alice as the user
# adduser alice
Adding user `alice' ...
Adding new group `alice' (1001) ...
Adding new user `alice' (1001) with group `alice' ...
Creating home directory `/home/alice' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for alice
Enter the new value, or press ENTER for the default
        Full Name []: Alice P Hacker
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] y
... Why does it care about the room number? haha

Wednesday, October 19, 2011

Give user sudo

You have to edit the /etc/sudoers file, which starts off with a scary text: This file MUST be edited with the 'visudo' command as root. OMG!

So I do visudo but it takes me to the nano editor.
I want vim instead! So I did export EDITOR="vim", which if you want to be your default editor, add this line to ~/.bashrc.

Copy and modify root   ALL=(ALL:ALL) ALL

Thursday, October 13, 2011

Setting up rackspace server

First I would like to say: thank you Rackspace, you have given me back the fire spark in life that has been swallowed by the fire hose.  Your superb user experience with instant server setup and live technical chat support has been a very pleasant surprise.  I can get all that for just $0.015/hour ($10.8/month)?

Anyways ... the things I did/learned from setting up my first Rackspace server:

1. Setting up apache for Python. I do want to run some Django apps, so I followed steps 1 and 2 of a previous setup.

2. DNS ... When I set up a domain name inside rackspace, it's going to be an internal lookup. I'll give my registered domain on name.com the general rackspace name. Then rackspace is going to do an internal lookup to find my specific machine that hosts the domain name.

3. History is found in ~/.bash_history


I created a user from root. How come the user only has sh shell but not the better bash shell like root?
Edit: I think there is more to it: useradd -D --shell <shell-to-set>

4. Check the shell with ps or echo $SHELL

5. Check the shell a particular user is running in /etc/passwd, or view it like grep username /etc/passwd

6. So I changed my user's entry in /etc/passwd from /bin/sh to /bin/bash

7. Move /bin/bash to the top of /etc/shells


Now my user has bash, but it doesn't have .bashrc. There is more to it.

8. Copy root's /etc/skel directory. "The /etc/skel directory contains files and directories that are automatically copied over to a new user's home directory when such user is created by the useradd program." ~ source 

It turns out that I do have them copied, but I have to manually copy them again into ~/, which I'll have to create first, but I need sudo powers for my user, see next post.

Wednesday, July 20, 2011

Preparing to Set up MozSecWorld on Linux

Since the permanent host for MozSecWorld will be on linux.

1. Install libapache2-mod-wsgi. This is a Python apache!
sudo apt-get install libapache2-mod-wsgi

2. Install Apache2. /etc/init.d/apache2 status should say that "Apache2 is running"

3. Configure Apache2.

4. clone repository git clone https://github.com/haoqili/MozSecWorld

5. Get the vendor. cd MozSecWorld/vendor and then git clone --recursive git://github.com/mozilla/playdoh-lib.git .
follow the Setup Section until
python manage.py runserver does not complain about any missing modules

Tuesday, June 21, 2011

Tuesday, May 24, 2011

Setting up a LAMP server (on my new XVM)

with help from bbaren

1. Log in:
         $ ssh username@vmname.xvm.mit.edu
2. Can you sudo? Try sudo bash, if you get an "username is not in the sudoers file.  This incident will be reported." error, do
         su -
         gpasswd -a username sudo
         grep sudo /etc/group should show results
         (If you want to give user sudo powers)
3. If everything worked, you should see "It works!" here http://vmname.xvm.mit.edu/
4. The "It works!" page is at /var/www/index.html

Done!

Extra stuff:

Configurations are in /etc/apache2/.
1. cd /etc/apache2/sites-enabled/
2. ls -l
total 0
lrwxrwxrwx 1 root root 26 2011-05-23 20:27 000-default -> ../sites-available/default

The following changes the sites-enabled to sym link to an edited version:
3. cd ../sites-available/
4. sudo cp default default_1
5. cd ../sites-enabled/
6. sudo rm 000-default
7. sudo ln -s ../sites-available/default_1 000-default
8. sudo /etc/init.d/apache2 reload

Thursday, January 27, 2011

Change prompt color (and others) on Linux terminal

Simple way:

> cd ~/
> vim .bashrc
> /force_color_prompt=yes
> delete the "#" in front of this line to uncomment it
> save (":w" in vim)

Open up a new terminal to see results!

----

The more complicated way lets you customize the prompt, you can google it.

Add date to the prompt:
key is adding the :\t: to the line, where you add ":" to separate it from other parts of the prompt. But then it would not be colored.

To add nice colors, wrap it with
:\[\033[01;33m\]\t\[\033[00m\]:

The \[\033[01;33m\] means it's the beginning of the color "33" is yellow in my case, feel free to pick another color. The \[\033[00m\] means you end this coloration.

In the end, I have this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\t\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '