fredag 18 juni 2010

Samba config without auth

Sometimes its been necessary to have a completely auth-less samba share without any username and password dialog popup, especially when scripting in Windows. It took me some time to figure out the Samba config, below is a stripped example of a working authless share. Tested with Windows Server 2008 and Windows 7, using samba 3.

Bold parts is the important ones.

#========= Global Settings =========#
[global]
workgroup = MYGROUP
server string = Samba Server

hosts allow = 10. 127.
load printers = no
guest account = nobody

log file = /var/log/samba/%m.log
max log size = 50

security = user
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
local master = no
map to guest = Bad User

socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
# interfaces = 192.168.12.2/24 192.168.13.2/24
dns proxy = no

idmap uid = 16777216-33554431
idmap gid = 16777216-33554431
template shell = /bin/false
winbind use default domain = no

#========= Share Definitions =========#

[no_auth_share]
comment = Share that does not need any authentication
path = /srv/snow
guest only = yes
guest ok = yes

onsdag 12 maj 2010

A good .screenrc config setup

GNU Screen is a great tool for keeping sessions alive even when exiting the ssh connection.
This ~/.screenrc config puts a nice bar at the bottom with a clock/date bar. It also put labels automatically when using the ssh command to connect to a new host, which is a real timesaver.



This ~/.screenrc configfile was of course found on the internet and has been modified.


# Statusbar
hardstatus alwayslastline "%{= KW} Screen(s): %-w%{= wk} %50>%n %t%{-}%+w%< %=%{KW}[%c %M %d %Y ]"


# Turn off start message:
startup_message off


# Set messages timeout to one second:
msgwait 2


# Shell path can be needed on some systems
#shell /usr/local/bin/bash


# Use a 30000-line scrollback buffer
defscrollback 30000


# Activity flash bar
activity "activity in %n (%t) [%w:%s]~"


# Run everything in UTF-8.
defutf8 on


defnonblock on
autodetach on


# Use the function keys to switch among windows.
#bindkey -k k1 select 1
#bindkey -k k2 select 2
#bindkey -k k3 select 3
#bindkey -k k4 select 4
#bindkey -k k5 select 5
#bindkey -k k6 select 6
#bindkey -k k7 select 7
#bindkey -k k8 select 8
#bindkey -k k9 select 9
#bindkey -k k; select 10
#bindkey -k F1 select 11
#bindkey -k F2 select 12


#bindkey -k F1 prev
#bindkey -k F2 next


# Window numbering starts at 1, not 0.
#bind c screen 1
#bind 0 select 10

To enable automatic title updating when jumping around with ssh, add this to ~/.bashrc:

function ssh() {
echo -n -e "\033k$1\033\134"
/usr/bin/ssh $@
echo -n -e "\033k`hostname -s`\033\134"
}
echo -n -e "\033k`hostname -s`\033\134"



Hardcore bash PS1 prompt

This is the PS1 bash prompt I've been using for a while now. It shows the line number in bash history and the latest exit code. As well as the common info such as username, hostname and full pathname. Put this line in the startscript for bash, for me its ~/.bashrc (in a quite recent ubuntu release). It might be needed in ~/.bash_login as well.
PS1=\!,$? \u@\h:\w\$
export PS1
Example:
502,0 username@hostname:/etc/init.d$ ls omgthisfiledoesnotexist
ls: cannot access omgthisfiledoesnotexist: No such file or directory
503,2 username@hostname:/etc/init.d$

With this PS1 prompt it's very easy to backtrace to where the command occured using the history command.

Passing commands to GNU screen session inside screen

Resuming a screen session with multiple windows inside another screen session can be a pain. Until today I've had no clue that commands easily could be transferred to the "inside screen session" simply by pressing
CTRL+a, a, [key]
For example, to detach a screen session inside another screen:
CTRL+a, a, d