Linux


12
May 12

Configure samba to share file between linux and win$

It’s really easy to share file between Linux-Linux which we can simply install
NFS then mount it easily from other computer.

But this article is to describe how to allow a Windows computer access
READ/WRITE to a Linux computer in a very quick, easy, simple way.

For Arch Linux, here is what I did to achieve above purpose.

1. Install samba package
sudo pacman -S samba
sudo pacman -S smbclient

2. Edit config file

By default, we have a sample config which you can copy and edit itself.
cp /etc/samba/smb.conf.default /etc/samba/smb.conf

And then, vim /etc/samba/smb.config

In [global] section, you may want to edit two line:

workgroup
server string

This is optinal so identify your computer easily on network

And then, go to [public] to edit it to your own need.:w
This section is to define public folder which everybody can access to it.

3. Adding user.

At this time, every thing is ready but you need to add an user with the same
name of one of the account on your system. Later, on Windows, once Windows user
go to Network > Linux Computer, they will be asked for an username/password.
They will need this password.

Because I’m using Linux under account lambasino so I run command:

sudo pbedit -a -u lambasino

And then I entered a password for this samba account. Remember, this is a
password for SAMBA, not password for current account under linux system so you
can enter anything you like. This username/password pair is to other user on other computer connect to your machine via it. This way your real password will be not exposed to the world. You give them samba username/pass instead.

4. Start samba server
sudo rc.d start samba

That’s all.

On Windows, go to, enter the username/password which you created as above. Ok,
it’s time to copy something fun over your LAN network ;P


4
May 12

Using homebrew to install anything got: “Error: Cannot write to /usr/local/Cellar”

I had a weird situation once I install anything with homebrew, I stucked at:


Error: Cannot write to /usr/local/Cellar

I do


ls -la /usr

and got this


loho:~ kureikain$ ls -la /usr
total 8
drwxr-xr-x@   13 root  wheel    442 May  4 12:42 .
drwxrwxr-t    27 root  admin    986 May  3 10:44 ..
drwxr-xr-x     8 root  wheel    272 Jul  2  2011 X11
lrwxr-xr-x     1 root  wheel      3 Dec  7 11:43 X11R6 -> X11
drwxr-xr-x  1058 root  wheel  35972 May  4 12:42 bin
drwxr-xr-x   288 root  wheel   9792 May  4 12:41 include
drwxr-xr-x   342 root  wheel  11628 May  4 12:42 lib
drwxr-xr-x   141 root  wheel   4794 May  4 12:42 libexec
drwxr-xr-x     7 root  wheel    238 Jan 27 18:32 llvm-gcc-4.2
drwxrwxr-x    10 root  admin    340 May  4 14:02 local
drwxr-xr-x   261 root  wheel   8874 May  4 12:42 sbin
drwxr-xr-x    69 root  wheel   2346 May  4 12:42 share
drwxr-xr-x     4 root  wheel    136 Jul  2  2011 standalone

For some reasons, /usr/local belongs to admin group insteads of wheel. with sudo, we need to have it in group “wheel”. I recall that this happened after I manually change the username. I had an account on Mac Mini with username “vinhnguyen”. I then decided to change it, so I manually enable root account and change the name of home folder. After I do that, /usr/local became to belong to admin group.

Futher, if I continue to check /usr/local, I got:


loho:~ kureikain$ ls -la /usr/local/
total 24
drwxrwxr-x  10 root        wheel  340 May  4 14:02 .
drwxr-xr-x@ 13 root        wheel  442 May  4 12:42 ..
-rw-r--r--   1 kureikain   admin  159 May  4 14:01 .gitignore
drwxr-xr-x   2 vinhnguyen  admin   68 May  4 11:10 Cellar
drwxrwxr-x   6 vinhnguyen  admin  204 May  2 12:06 Library
-rw-r--r--   1 kureikain   admin  789 May  4 14:02 README.md
drwxrwxr-x   3 vinhnguyen  admin  102 May  4 14:02 bin
lrwxr-xr-x   1 root        wheel   27 May  3 10:04 mysql -> mysql-5.5.23-osx10.6-x86_64
drwxr-xr-x  16 root        wheel  544 Mar 30 00:33 mysql-5.5.23-osx10.6-x86_64
drwxrwxr-x   3 vinhnguyen  admin  102 May  2 12:06 share

You may get following error:

Error: Permission denied - /usr/local/include

So, I can say permission got messing up after I manually change account name from vinhnguyen to kureikain. So we need to manually correct permission again.


sudo chgrp wheel /usr/local/

sudo chown -R $USER /usr/local/

After you do that, everything should work fine.

 


loho:~ kureikain$ brew install wget
==> Downloading http://ftpmirror.gnu.org/wget/wget-1.13.4.tar.bz2
Already downloaded: /Library/Caches/Homebrew/wget-1.13.4.tar.bz2
==> ./configure --disable-debug --prefix=/usr/local/Cellar/wget/1.13.4 --sysconf
==> make install
/usr/local/Cellar/wget/1.13.4: 7 files, 552K, built in 34 seconds

 


22
Apr 12

Copy to clipboard from command line on Linux and MacOSX

Sometimes it’s really tough when dealing with clipboard to between terminal and a GUI app. For example, you may need to get the content of id_rsa.pub and paste into browser. In the beginning, I simply fire up a text editor, copy content then paste into browser. Or sometime I highlight text in terminal and use mouse’s middle button to paste text into browser. But it actually has a simpler way to achieve this purpose.

Let use utility pbcopy


pbcopy < /path/to/file/need/to/copy/its/content

After that your clipboard will be fill in with file’s content.

 

 


16
Mar 12

VsFtpd cannot list directory

Normally when we are able to connect to a FTP server. We can see the directory, browser the files, upload/download. But it has a situation which prevents us from listing directory. As the result, we got kick out from server.

This error somehow causes by Iptables. When I turned off iptables, I can list the file. When I stopped “iptable” daemon, it works as expected. I’m surely that I config iptable to allow connection on port 21.

If you encounters this problem is this article is right way for you. When I googled about this error, I found a solution here:

http://serverfault.com/questions/224591/iptables-lets-me-connect-by-ftp-but-i-cant-get-dir-listing

http://serverfault.com/questions/131635/iptables-how-to-allow-incoming-ftp-traffic

The solution I used to solve this problem is to add this rule to iptables:

1.iptables -A INPUT -p tcp –dport 21 -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT

Actually, I just open the file /etc/iptables/iptables.rule and inject the rule there

2.Second, I load module modprobe nf_conntrack_ftp

modprobe nf_conntrack_ftp

Because of using Arch, I just open /etc/rc.conf and edit MODULES array like this:

MODULES=(nf_conntrack_ftp)

That’s all I got to get VsFtpd works again for me.


4
Mar 12

Cannot run xfce4-sensors

If in a beautiful summer day you worry how many temp your computer got and try to fire up xfce4-sensors and it show up sth like:

Segment fault

In that case, just make sure hddtemp daemon is up and running.

You should add hddtemp to DAEMON in /etc/rc.conf


17
Sep 11

Simple mail server for sending mail only

I used Google App for my email and it’s working great. The problem is I used a VPS and I need to send email on my system. I can configure to send email via google smtp. But somehow google stops to sending email when my system send email every 5 minutes. And sometimes Gooogle delays to delivery emails too.

Finally I decided to install a mail server for my own using. All I need is mail sending only. Receiving email is taken care by google app.

I used Arch Linux. All I need is to configure postfix, IMHO Postfix configuration is so complex to understand all of its aspects. Luckily we just want to send email so it should be simple ;)

pacman -S postfix

Next, open /etc/postfix/main.cf, add these value (change to your own domain):

myhostname = www.axcoto.com
myorigin = axcoto.com

Add postfix daemon to DAEMON in /etc/rc.conf.

DAEMONS=(syslog-ng !network netfs crond dbus @alsa wicd  httpd mysqld vsftpd postgresql !hwclock ntpd <strong>postfix</strong>)

That’s all for sending email ;) . Please don’t ask more about Postfix ;) . I don’t know haha. This is just I got to sent out email ;) .


3
Sep 11

Trac common errors and solutions

Trac is cool but it is not easy to use on the very first time. Most of its error are about permission, missing fields.

1) TimeoutError: Unable to get database connection within 0 seconds. (TracError(<babel.support.LazyProxy object at 0x341b1e0>,))

This error is caused by permission issue. Trac cannot read config file. Just chmod or chgrp to add read permission for user which is running trac. Normally, this is the user which run web server which is serving trac. If you use mod_wsgi with apache, it can be “http” user, if you use tracd, it is the user which you issued tracd on.

2) GitError: GIT control files not found, maybe wrong directory?

Because GitPlugin cannot read git information. The user which is running Trac doesn’t have that permission to read Git repo. You can chmod or chown, chgrp. But later when you commit again, the permission can be reset by git, so you maybe need to set a default umask. Also if you are using Gitolite, you can want to set umask in .gitolite.rc to 0027 to allow group have read permission.

3) Missing fields
For some reasons, you can manually remove some fields of other plugins accidentally. You need to re-add them. For a simple way, install http://trac-hacks.org/wiki/CustomFieldAdminPlugin to create fields yourself.


28
Aug 11

Cross Compile

When you do cross-compiling, the compiler doesn’t know information of target platform such as: size of some data type, the const, flag, specification of compiler on that platform,..

For examples, you can got something like this:

check­ing for grow­ing stack pointer… con­fig­ure: error: can­not run test pro­gram while cross com­pil­ing
See ‘config.log’ for more details.
checking for posix getpwuid_r... (cached) yes
checking for posix getgrgid_r... configure: error: in `/8652_3110_tango/libraries/glib-2.20.4':

So we must let compiler know himself via a special cache file which can be specified via param –-cache-file when executing configure. If we name it config.cache then we do configure –cache-file=config.cache. Basically, we manually add defination for those value, flag, constm,…
You maybe to gooogle or read document of software which you are compiling carefully to find out name of those flags, consts. Reading any errors which you see, google them then append to the cache file

Mine looks like this when compiling glibc for SMP86xx chip (Use http://www.codesourcery.com/ toolchain)

ac_cv_func_posix_getpwuid_r=${ac_cv_func_posix_getpwuid_r=yes}
glib_cv_stack_grows=${glib_cv_stack_grows=no}
glib_cv_uscore=${glib_cv_uscore=no}

samba_cv_CC_NEGATIVE_ENUM_VALUES=yes
ac_cv_func_getpgrp_void=no
ac_cv_func_setpgrp_void=yes
ac_cv_func_memcmp_working=yes
rb_cv_binary_elf=no
rb_cv_negative_time_t=no

If you have enough C/C++ knowledge, you can easily find out the name of flag, definition and manually set value for them. Unfortunately, it can be not a simple job so just gooogle it or read docuement as I did ;) .

So the idea is to manually define flags of target platform which current platform (compiler) doesn’t know about it. That’s all.


21
Jul 11

Remove all junk svn stuff

I hate SVN, you will not know how much I hate it. When think of fucking days with it, I always wonder how I can live on it. Nowadays, as long as I see SVN, i always keep away from it! Not like Mercurial or Git, SVN always keep a .svn folder in every directorys of your project! Of course I want to get rid of these stuffs! In the first part of my life, I always wrote bash script to do this task:

#!/bin/bash
value=0;

while read line
do
echo "rm -R  \"/home/kureikain/www/folio1/$line\""
rm  -R  /home/kureikain/www/folio1/$line
done < "svn-del"

echo $value;

Later I see some tutorials which use power of -exec param, It was really cool:

find . -name .svn -exec 'rm -rf {}\;'

Actually -exec is a powerful parameter which I will write about it in another article. Right now, we just go with above command to remove all svn stuff ;) . After 3 years with Linux, I understand an important thing: my command line fu is really bad :( (!


20
Jul 11

Remove entry from know_hosts of ssh

I recently switch to other VPS! Becasue of this when I ssh to new VPS (with the same domain), I got this:


[lambasino@lambasino ~]$ ssh axcoto.com -l kureikain
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for axcoto.com has changed,
and the key for the corresponding IP address 208.111.35.209
has a different value. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
Offending key for IP in /home/lambasino/.ssh/known_hosts:4
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
fa:87:6d:54:d1:39:23:f6:78:fb:46:07:13:00:3a:1d.
Please contact your system administrator.
Add correct host key in /home/lambasino/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/lambasino/.ssh/known_hosts:1
ECDSA host key for axcoto.com has changed and you have requested strict checking.
Host key verification failed.
[lambasino@lambasino ~]$

So, it turns because of the different of key in old VPS and new VPS! Of course I must remove entry for axcoto.com in my known_hosts to force ssh add host key again!

I open vim and remove that line – line which start with axcoto.com!

But I think it must have some better way or more regular way instead of hard-coding it! It turns out very easy to do it! Just use

ssh-keygen but with -R switch!


[lambasino@lambasino ~]$ ssh-keygen -R axcoto.com
/home/lambasino/.ssh/known_hosts updated.
Original contents retained as /home/lambasino/.ssh/known_hosts.old

Remember to remove IP too if you used IP for connecting before!