Tag Archives: debian

Quick guide to config a samba server on debian to share files between windows and linux

It comes handy to setup samba server on a linux computer, for example: debian, and from there you will be able to share files to windows, the linux computer could be used as a windows computer provide file share. And you can access directory structure from a windows explorer:

access linux directory through samba from windows explorer

access linux directory through samba from windows explorer

There is already a great step by step guide here: http://www.unixmen.com/standalone-samba-in-debian-squeeze/

For me, I know the general idea and only need a quick reference to go for, so I listed a shorten steps below:
Install:
apt-get install samba

Edit the config file:
emacs /etc/samba/smb.conf

Add the content below to the end of the file:
[website]
comment = website
path = /website
valid users = @root
create mask = 0744
directory mask = 0744
writable = yes

Add username to samba:
smbpasswd -a root

Looks like it is required to add your username to samba’s own tracked list of allowed users: (of course you can add other users instead of root in your linux server, I use root here because I only want to setup a test machine for develop purpose)

Restart the server:
/etc/init.d/samba restart

That’s it, follow this quick list, you will be able to start a samba in 2 minutes for some quick use. But if you are looking for serious use, you’d better read&understand each config item in the manual.

Last by not least, an even short copy&paste block for you to make a quick start:

apt-get install samba
emacs /etc/samba/smb.conf

[website]
comment = website
path = /website
valid users = @root
create mask = 0744
directory mask = 0744
writable = yes

smbpasswd -a root
/etc/init.d/samba restart

Avoid boot stopper: give root password for maintenance

When messed around, you will get a message: give root password for maintenance, and require you to press ctrl+D to continue during linux boot, then freeze the boot process. Most likely, it is because it’s booting into the single user mode.

To have the linux boot without this blocking issue, open file: /boot/grub/menu.lst, and set the default option to the config with a quiet in it, the index is zero based, so in my case, here is my config file, I am setting it to take the config with this line:

kernel          /boot/vmlinuz-2.6.32-5-xen-amd64 root=/dev/xvda1 ro quiet

root@debian-linux:~# cat /boot/grub/menu.lst
default 0
timeout 5
title           Debian GNU/Linux, kernel 2.6.32-5-xen-amd64
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.32-5-xen-amd64 root=/dev/xvda1 ro quiet
initrd          /boot/initrd.img-2.6.32-5-xen-amd64

title           Debian GNU/Linux, kernel 2.6.32-5-xen-amd64 (single-user mode)
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.32-5-xen-amd64 root=/dev/xvda1 ro single
initrd          /boot/initrd.img-2.6.32-5-xen-amd64

debian reload interface config after made changes to file: interface

When working on debian through ssh, if you’ve made changes to file: /etc/network/interface, run the command below to reload&apply the changes and avoid to reboot or reconnect ssh:
/etc/init.d/networking restart

unzip 7z file on debian (linux)

To upzip .7z file on the debian (linux), you need to

  1. Install the package with:
    apt-get install p7zip
  2. If your file to unzip is: test.7z, then run:
    7zr x test.7z

Going further, for a list of parameter type:
7zr --help
And you will get:

7-Zip (A) 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30
p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)

Usage: 7zr  [...] [...]
[]
a: Add files to archive
b: Benchmark
d: Delete files from archive
e: Extract files from archive (without using directory names)
l: List contents of archive
t: Test integrity of archive
u: Update files to archive
x: eXtract files with full paths

-ai[r[-|0]]{@listfile|!wildcard}: Include archives
-ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
-bd: Disable percentage indicator
-i[r[-|0]]{@listfile|!wildcard}: Include filenames
-m{Parameters}: set compression Method (see the manual)
-l: don't store symlinks; store the files/directories they point to
CAUTION : the scanning stage can never end because of symlinks like '..'
(ex: ln -s .. ldir)
-o{Directory}: set Output directory
-r[-|0]: Recurse subdirectories
(CAUTION: this flag does not do what you think, avoid using it)
-sfx[{name}]: Create SFX archive
-si[{name}]: read data from stdin
-slt: show technical information for l (List) command
-so: write data to stdout (eg: 7zr a dummy -tgzip -so Doc.txt > archive.gz)
-ssc[-]: set sensitive case mode
-t{Type}: Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
-v{Size}[b|k|m|g]: Create volumes
-w[{path}]: assign Work directory. Empty path means a temporary directory
-x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
-y: assume Yes on all queries

Useful pptpd server – poptop admin command

Here are a few commands useful for pptpd server admin:

Find out who is Online:

last | grep ppp | grep still

Get a list of user’s connection time:

ac -d -p
If you don’t have ac on your server, run:
apt-get install acct

Disconnect a User

  1. find out user’s ip (we know it from “Find out who is Online” part)
  2. use command below to find out process id
    ps -ef | grep | grep pppd
  3. end user’s process
    kill <process id>

Further Reading:

pptpd server – poptop document

psacct is known as acct in debian

If you are trying to install psacct in debian, you will get an error message:
E: Unable to locate package psacct
It is because it’s called acct in debian:
So, let do this:
apt-get install acct
But the way, I am still not getting used to:
aptitude install acct

Install and setup pptp vpn on debian (pptp 101)

Please follow these steps if you want to setup a pptp vpn from debian:

1. SSH into the debian server

2. Install pptpd with command:

apt-get install pptpd

3. Setup host ip and client ip range. Open file: /etc/pptpd.conf with text editor, and at the content below at the end:

localip 192.168.0.40
remoteip 192.168.0.234-238,192.168.0.245

localip is the ip of your server in the virtual network, remote ip the pool range of the client, will assigned by the server automatically when client connects in. Also, please use the ip range not already use in your real lan, my home lan is in 192.168.1.x, so here I use 192.168.0.x

4. Config pptp dns, open file /etc/ppp/options.pptpd, find the line ms-dns and setup as below:

ms-dns 8.8.8.8
ms-dns 8.8.4.4

Here I setup with google dns, you are free to use your own dns if you have. But safe with google.

5. Setup client account, open file: /etc/ppp/chap-secrets, and add the line like this:

testuser pptpd testpassword *

testuser is the username, testpassword is the password of the client.

6. Setup ip forward in /etc/sysctl.conf, find the line net.ipv4.ip_forward and edit like below:

net.ipv4.ip_forward=1

save the config and run the command below to load the setting:

run sysctl –p

7. Setup iptables, run command like this:

iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

Change the 192.168.0.0 to match the value you use in step 3. And you may need be to change eth0 to other values where your internet connection is on.

This is all the steps you need to setup the pptp server. Now you can setup a connection in Control Panel\All Control Panel Items\Network and Sharing Center:

windows pptp client setup

Click the link as the red box show above, and follow the wizard to setup a vpn connect and make a test run.

Know issues:

If you have successfully setup the pptp vpn and able to access websites from it, but you are experiencing strange problem and can’t access some of the sites like: www.alexa.com, check my post here for a possible fix: Can’t access certain sites with pptp

Further Reading:

To setup a IPSec L2TP VPN, you may want to look here:

Setting up an L2TP/IPSec server on Debian
Setting Up an IPSec L2TP VPN server on Ubuntu for Windows clients