Linux
Linux: Set IP address through shell
by Ali on Jan.09, 2009, under Linux
To change IP address immediately:
ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up or ifonfig eth0 192.168.1.10/24
route add default gw 192.168.1.1
echo nameserver 192.168.1.1 > /etc/resolv.conf
Linux: User management
by Ali on Jan.02, 2009, under Linux
useradd: Add new users commands:
-d specify home directory
-s shell
-p specify password
-g user’s primary group
-G user’s other group
-m create home directory
The following command creates a user “ali”, adds to groups users and admin and create his home directory:
useradd -g users -G admin -p <password> -d /home/ali -m ali -s /bin/shell
usermod: Modify existing users
Use above switches to modify a user
Add “ali” to another group:
usermod -G <groupname> ali
userdel: Delete a user
Removes the user “ali”. To delete home directories use -r switch:
userdel -r ali
passwd: user Password
Logged on users can just use passwd to change their password. If root is changing a user’s password:
passwd <username>
su: switch user
To switch from current user to another:
su <username>
You may switch from root to another user without entering user’s password, but not the other way around. This will not log off current user. To return to previous user shell type “exit”.
Users, passwords and group information are stored in these files:
Users: /etc/passwd
Groups: /etc/group
Passwords: /etc/shadow
Linux: Mount remote Windows shares with smbfs
by Ali on Dec.31, 2008, under Linux
It’s actually quite easy!
In Debian you will have to install smbfs. Some distros install this package by default. First create a mount point to which we will refer to as /mountpoint from this point forward.
mkdir /mnt/mountpoint
To mount:
mount -t smbfs -o username=<username>,password=<password>,workgroup=<workgroup/domain> //servername/share /mountpoint
If you don’t want to type your password in the comman then don’t. Remove password=<password> and you will be asked to enter it once you hit enter. To use local credentials use the server name in <workgroup/domain> and to use domain credentials use the domain name. Username must match the domain or server you are authenticating against.
You can also mount admin shares. Instead of //servername/share use //servername/<driveletter>$
You can ultimately auto mount remote shares during boot by adding those lines to your fstab, but if your Linux box is not a member of the domain and can’t authenticate mount process will fail unless you have smbfs authenticate automatically. This is not the safest way of auto mounting shares in Linux as you are going to store your password in a text file. As precaution you can make the file accessible to root only.
To do so, add this line to your fstab:
//servername/sharename /mountpoint smbfs auto,credentials=/root/.passfile,uid=1000,umask=000,user 0 0
/root/.passfile is where you will store your network passwords. Create it and add the credentials:
nano /root/.passfile
Then add the following lines:
username=<username>
password=<password>
To make the file readable by root only:
chmod 600 /root/.passfile
Once you’re done with all this, go ahead and mount the shares:
mount -a
Remote share will be mounted automatically after every reboot.
Linux: Cannot turn on a virtual machine after unclean shutdown – failed to lock the file error VMware Server
by Ali on Dec.30, 2008, under Linux, VMware
I don’t recall the exact error message, but sometime after an unclean shutdown your virtual machines will not start with an error that contains “unable to unlock file”. To resolve the issue simply navigate to the directory where your virtual machine resides, and delete all files with .WRITELOCK and .lck extension.That should remove the lock and make your VM’s accessible. If that didn’t help, go ahead and delete all files EXCEPT .vmdk AND .vmx EXTENSIONS. That should definitely do the trick.
You can actually delete the .vmx files as well but in order to have VMware recreate them you will have to start the “new virtual machine wizard” and use the .vmdk as your disk file. Instead of creating a disk you use an existing.
Linux: tar tips and tricks
by Ali on Dec.14, 2008, under Linux
To untar a tar file:
tar xf filename.tar
To untar a tar.gz or tar.tgz (gzip) file:
tar -zxf filename.tar.(t)gz
To untar a tar.bz (bzip) file:
tar -jxf filename.tar.bz
To untar a tar.bz2 (bzip2) file:
tar -yxf filename.tar.bz2
To view a list of files in an archive:
tar -tzf filename.tar.gz
If the archive contains numerous files and you’d like to be able to view line by line:
tar -tzf filename.tar.gz | more
To untar an archive to a different directory:
tar -zxf filename.tar.gz -C <directory>