You searched for articles tagged with Linux.

[ #149 ] Yesterday's Date Permalink

Shell, Linux Added less than a year ago

Using date you can do some nifty things with human-readable dates:

$ date +%Y%m%d
20090915
$ date -d '1 day ago' +%Y%m%d
20090914

This works with the date that comes with my Slackware distribution (and probably most/all Linux distributions) but not with my Mac OS X date.




[ #116 ] CTWM Config Permalink

Linux, X Added a year and a bit ago

I have been using CTWM as my window manager on my Debian VM for a while now, here is the config (.ctwmrc) file. Put it in your home directory and adjust your .xinitrc accordingly.

The setup I have uses 4 workspaces, you can't drag windows off the screen and it has a simple menu mainly for launching xterms in nice places. It is setup for the resolution 1280x800 (my macbook.)

NoGrabServer
NoTitleHighlight
NoIconManagers
DontMoveOff
RestartPreviousState
DecorateTransients
TitleButtonBorderWidth 1
NoHighlight
BorderWidth 2
TitleFont       "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
ResizeFont      "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
MenuFont        "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
IconFont        "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
IconManagerFont "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
ShowWorkSpaceManager
WorkSpaceManagerGeometry "360x18+458+780" 4
WMgrButtonShadowDepth 0
WMgrHorizButtonIndent 0
WMgrVertButtonIndent 0
BorderWidth 1 
NoTitle { "WorkSpaceManager" "xterm" }

WorkSpaces
{
    ""   {"#5de100" "white" "black" "black" "black"}
    ""   {"#1f1ab2" "white" "black" "black" "black"}
    ""   {"#ffc200" "white" "black" "black" "black"}
    ""   {"#e7003e" "white" "black" "black" "black"}
}


Color
{
    BorderColor         "#ffc201"
    DefaultBackground   "black"
    DefaultForeground   "black"
    TitleBackground     "#ffc201"
    TitleForeground     "white"
    MenuBackground      "black"
    MenuForeground      "#ffc201"
    MenuTitleBackground "#ffc201"
    MenuTitleForeground "black"
    IconBackground      "black"
    IconForeground      "#ffc201"
    IconBorderColor     "black"
}

MoveDelta 3
Function "move-or-lower" { f.move f.deltastop f.lower }
Function "move-or-raise" { f.move f.deltastop f.raise }
Function "move-or-iconify" { f.move f.deltastop f.iconify }

Button1 = : root : f.menu "defops"
Button2 = : root : f.delete
Button1 = m : window|icon : f.function "move-or-lower"
Button2 = m : window|icon : f.iconify
Button3 = m : window|icon : f.function "move-or-raise"

Button1 = : title : f.function "move-or-raise"
Button2 = : title : f.raiselower

Button1 = : icon : f.function "move-or-iconify"
Button2 = : icon : f.iconify

Button1 = : iconmgr : f.iconify
Button2 = : iconmgr : f.iconify

menu "quit" {
    "Quit X?"   f.title
    "quit"    f.quit 
}

menu "defops"
{
"YourHost"     f.title
"(L) xterm"   f.exec "exec xterm -ls -fg gray -bg black -sl 500 +sb -geometry '104x57+0+18' &"
"(R) xterm"   f.exec "exec xterm -ls -fg gray -bg black -sl 500 +sb -geometry '104x57+648+18' &"
"(Big) xterm" f.exec "exec xterm -ls -fg gray -bg black -sl 500 +sb -geometry '212x57+0+18' &"
"gvim"        f.exec "exec gvim &"
#"conky"      f.exec "exec conky &"
"vm tools"    f.exec "exec vmware-toolbox &"
#"iceape"     f.exec "exec iceape &"
#"firefox"    f.exec "exec firefox &"
"kill"        f.destroy
"restart"     f.restart
"quit"        f.menu "quit"
}



[ #92 ] Secure HTTP Tunnel Permalink

Linux, Shell, Privacy, SSH Added a year and a bit ago and last edited a year and a bit ago

The Stupid Way

(Don't do this, see The Smart Way below)

On a remote machine that you have SSH access to:

remote$ hostname
host.where.proxy.is.running
remote$ # start an HTTP proxy running on port 8887 here

Then, on your local machine:

local$ ssh -qnN -L 8080:localhost:8887 host.where.proxy.is.running.tld &

... and setup your browser to use localhost:8080 as the proxy.

The proxy software I use on my remote host is TinyProxy

The Smart Way

You don't even need to setup a proxy at your remote host if you just create a tunnel like this:

local$ ssh -qnN -D 1080 remotehost &

... that will setup a tunnel from on your local machine from localhost:1080 over to remote, and then use the remote server to just send any requests you make through there... like a relay. So if you set your browser to use the SOCKS proxy on localhost:1080 then you have a tunnel without having to setup any proxy software. Thanks Snare!




[ #88 ] BSD Terminal Niggles Permalink

*BSD, Shell, Linux Added a year and a bit ago

In my BSD VMs (I am using an OpenBSD one at the moment), there are certain display settings that I like to change to emulate the default "terminal" settings on Linux. (I quote "terminal" here because we're not really messing with termcaps or anything hardcore.)

Why doesn't Ctrl-L clear the screen?

I install Bash to do this :-) The default shells for *BSD are often ksh or csh and it seems that Ctrl-L is not set-up to clear the screen on these shells. There is probably a better way to do this but I like Bash anyway, even if it is bloated.

Why doesn't .bashrc get read?

Put your commands/setup code in .bash_profile - or include .bashrc from .bash_profile

Fix your default pager

The default pager on *BSD is often set to more. You want to make it less.

$ export PAGER=less

This will make it so when you look at a man page and you scroll to the bottom of the page using G it doesn't quit back to the shell, it stays in the man page! This annoyed me so much!




[ #86 ] SSH Config Permalink

Linux, Shell, SSH Added a year and a bit ago and last edited less than a year ago

Users

If you are on a system as user fredb and you want to ssh to a host where your login is superman, you would normally have to specify the username on the ssh line like so:

fredb@thishost$ ssh superman@otherhost

... but you can save yourself some typing by specifying that a ssh to otherhost should try to login as superman every time by adding some lines to your ~/.ssh/config file:

Host otherhost
    User superman

Now you can simply do this:

fredb@thishost$ ssh otherhost

... and it will ask for superman's password instead of fredb's.

Host Nicknames

You can also use your config file to specify host nicknames. Say you normally connect to longhostname.tld, you can shorten that to lhn if you like:

Host lhn
    Hostname longhostname.tld
    User jsmith

... now you simply:

$ ssh lhn

Identity Files (Keys)

If you have keys set up for your various hosts, and those keys are loaded in your ssh-agent, you might like to specify which key belongs to which host in the config file.

Host lhn
    Hostname longhostname.tld
    User jsmith
    IdentityFile ~/.ssh/id_dsa.longhostname

This is important if you have greater than 6 keys in your agent. Why? Because without this mapping, ssh-agent will iterate through its list of keys until it finds one that works - but the host will hang up after 6 unsuccessful tries! If your key is number seven in the list then it will not work. So, adding the IdentityFile mapping in the config file as above will make ssh-agent try the correct key the very first time.




[ #81 ] Linux Groups and Login Permalink

Linux, Shell Added a year and a bit ago and last edited a year and a bit ago

Bob was experiencing something funny on Debian:

bob@local $ groups
bob wheel
bob@local $ sudo groups bob
bob wheel www-data othergroup

Turns out that groups are applied to a user on login only, and bob was added to the extra two groups after his last login. So once bob logged-out and back in again:

bob@local $ groups
bob wheel www-data othergroup

... everything was right with the world. Thanks Rendrag!




[ #57 ] chmod and umask Gotchas (Got Me Anyway) Permalink

Shell, Linux Added a year and a bit ago and last edited a year and a bit ago

Every file in unix has a set of permissions. They are (r)ead, (w)rite, and e(x)ecute for each of these three types of people: (u)ser who owns the file, members of the (g)roup that own the file and (o)ther people on the system.

Mnemonic: RWX = running with scissors (X is a pair of scissors, right???)

$ ls -hl
total 0
-rw-r--r-- 1 frank users 0 2009-02-04 15:47 one
-rw-r--r-- 1 frank users 0 2009-02-04 15:47 three
-rw-r--r-- 1 frank users 0 2009-02-04 15:47 two
d123456789    a      b

Note: e(x)ecute means it's a binary or a script that you can run like this: ./scriptname -or- if the 'file' is a directory it means you can cd into it and look around.

If you are on a shared hosting environment, and you have nothing to do with anyone else on the system, and have heaps of files you don't want publicly visible, you could do one of two things:

Method (1) Use chmod to remove all (o)ther permissions on all your files -or-

Method (2) Use chmod to remove the e(x)ecutable bit of the (o)ther permission on your home directory only

The first option is natural enough, let's walk through it: You are user frank. Another user on your shared hosting environment is user bill. You have three files in your home directory, /home/frank called one, two and three. To make sure all the (o)ther permissions on these files are removed (so that bill can neither (r)ead, (w)rite or e(x)ecute those three files), do something like this:

$ chmod o-rwx one two three

The o means other, the - means remove, the rwx is the list of permissions to remove.

Let's examine the second option:

$ chmod o-x /home/frank

If any directory on the way to a file is o-x then others can not list, view, change or execute that file.

But wait: what if the file one was owned by the user frank and owned by the group users? And let's say that bill is in the group users too... well, bill can still see one until the (g)roup permissions are removed from it or the (g)roup e(x)ecutable is removed from a containing directory. Because in this case, bill is not an (o)ther user - he is a (g)roup user (a user in the same group as that which owns the file.)

Confusing?

A note about method 2: If you are frank, in the group users, and you have a directory in your home directory named htdocs that is owned by apache:apache (and obviously is used to serve web pages) then this method will break your webserver! Why? Because in the chain /home/frank/htdocs there is an o-x (on /home/frank) which means that (o)thers (like apache) can not read the htdocs dir. So this is not a good method if you have a setup like this.

umask is the utility that tells you what permissions a file has when you first create it (and don't specifically chmod it.) Sometimes you'll get a umask like this:

$ umask
  0022

The last three numbers mean what is taken away (subtracted) from 7 from each of the three types, (u) (g) and (o). What has 7 got to do with it? Well:

If a file has all bits set for, say, the (u)ser type then the (u)ser will be able to read, write and execute the file.

So if your umask is 0022 (ignore the first number for this exercise, only take notice of 022) then by default your files are going to be created like this:

But here's the twist: the (x) only takes effect if the 'file' you've just created is a directory. Otherwise ignore it. So with the above umask of 022 it would be ugo = 755 for a newly created dir and ugo = 644 for a newly created file.

Ever seen someone chmod a file with numbers like this?

$ chmod 640 three

They have just made the file named three: (r)eadable and (w)riteable by the (u)ser (r + w = 4 + 2 = 6), (r)eadable by the owning (g)roup (4 = w), and neither (r)eadable, (w)riteable or e(x)ecutable by (o)thers (0 = no permissions.)

A umask of 027 is a better way to go than 022. Set it like this:

$ umask 0027

I will keep re-reading this post to see if there are any errors in it - it is a confusing topic :-)




[ #55 ] Fixing Small Fonts in X Permalink

Linux, X Added a year and a bit ago

I was running avahi-discover on X and noticed the fonts came up very small - they were unreadable. To remedy the situation I measured my monitor with a ruler (I'm not joking) and got the breadth x height in millimetres (288mm x 182mm on my Macbook.) Then I changed my /etc/X11/xorg.conf file, adding one line:

Section "Monitor"
    ...
    DisplaySize     288 182
    ...

Then restarted X. It worked great! Thanks to this howto.




[ #53 ] Which Libraries Does This Binary Use? Permalink

Linux, Shell Added a year and a bit ago

If, under Linux, you have an executable (binary) and you want to find out which libs it uses, try this:

$ ldd /path/to/bin

This is very useful when you are putting bins in a chroot environment - you need to include the libs in there too otherwise they won't work.




(Nothing Older) ... Newer Posts

Colophon

Django Python 960.gs Git Vim NetBSD Nginx

The Author

This is the blog of Brad Willis, a software engineer living in Brisbane.

Meta

Help
Latest entries

*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh

Recent Entries

Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?
Why is swap space important?
Perldoc Output
Git's Index
Jira Project Keys
Git GUI

Links

ChoppingBoard, DaveMisc, Project365, RageQuit