Tips and Tricks About Computers, Web Development, Linux, the Internet and the Like
Archive for September, 2010
Random gnome-terminal profiles (themes) in Ubuntu
Sep 30th
Posted by Tyler Mulligan in Application Management
Introduction
Does it ever confuse you if you have too many terminals open at once that look alike? Perhaps you’re just looking to express your personality or tickle your brain. In any case, if you’re using the terminal in ubuntu a lot, you may be interested in having random profiles (colors / settings).
The concept of the method is pretty simple, define a hotkey that launches a script that picks a random profile you’ve created and then open the terminal with that profile as a parameter.
Prerequisites
- Compiz or other hotkey script that will allow you to link to a .sh file
- gnome-terminal
- bash
Getting Started
You can figure out what Profiles you have by going to Edit > Profiles in gnome-terminal. You likely only have one, “Default”, unless you’re already actively using terminal profiles. If you only have one, you should create a few, maybe 3 or 4 right now and play with the colors a bit. Important, don’t include spaces in the names of the profiles
The Script
Create a file in your scripts folder (or create a directory if you don’t have one):
mkdir ~/scripts touch ~/scripts/gnome-terminal.sh && chmod +x ~/scripts/gnome-terminal.sh gedit ~/scripts/gnome-terminal.sh
Paste the following replacing the Profile names with those of your own (delimited by spaces) and change the number 4 to that of the :
#!/bin/bash
p=( Default Delta Psi Sigma )
gnome-terminal --window-with-profile ${p[$((RANDOM%${#p[@]}))]}
That ugly looking bit right here is a calculation between a random number (echo RANDOM) and the size of the array (${#p[@]}), “random” % “length of array”. Where % means mod, or remainder of the division. (examples: 7%4 = 3; 6%4 = 2; 5%4 = 1; 4 % 4 = 0; 4 % 3 = 1; 321%321= 0).
To illustrate more, play with this code:
r=$RANDOM; echo $r; echo $((r % 4))
This is how we get a random index value for the array. This value is nested inside the array ${p[r]}, where r is the random, within bounds, array index. That array then corresponds with a name of our profile and we pass it as a paramater to gnome-terminal with “–window-with-profile”. So using my define array above, if the random index were “1″, “Delta” would be echoed. If the index were “0″, Default would be.
The Setup
Now, I use compiz with the commands plugin, setting my “command line 0″ to ~/scripts/./gnome-terminal.sh and my “run command 0″ under my key bindings tab to ctrl+alt+t, but you can associate this script with anything you’d like to kick it off. A shortcut icon for example.
May this inspire you to understand, extend and share.
Restricting a user’s shell permissions on Ubuntu Server 10.04 with lshell
Sep 27th
Posted by Tyler Mulligan in Bash
As described by apt-cache, the method which I usually begin a package search for in a Ubuntu Server 10.04 environment:
z@zentury ~$ apt-cache search lshell lshell - restricts a user's shell environment to limited sets of commands
This is an extremely useful way to restrict a Linux users capabilities. Alternative shells, such as rssh, limit you to toggle a specific set of applications, (scp, sftp, cvs, svn, rsync or rdist). A limited shell is helpful for reasons such as backups or game/application servers where you know/want the user to be able to execute only a specific set of actions. You can however, consider other reasons for restricting users on a Linux based machine.
A typical use case is provided in the lshell wiki.
Ubuntu also provides a default in etc/lshell.conf, which serves as a good example:
# lshell.py configuration file
#
# $Id: lshell.conf,v 1.20 2009/06/09 19:53:46 ghantoos Exp $
[global]
## log directory (default /var/log/lshell/ )
logpath : /var/log/lshell/
## set log level to 0, 1, 2 or 3 (0: no logs, 1: least verbose)
loglevel : 2
## configure log file name (default is %u i.e. username.log)
#logfilename : %y%m%d-%u
[default]
## a list of the allowed commands or 'all' to allow all commands in user's PATH
allowed : ['ls','echo','cd','ll']
## a list of forbidden character or commands
forbidden : [';', '&', '|','`','>','<', '$(', '${']
## number of warnings when user enters a forbidden value before getting
## exited from lshell
warning_counter : 2
## command aliases list (similar to bash’s alias directive)
aliases : {'ll':'ls -l', 'vi':'vim'}
## a value in seconds for the session timer
#timer : 5
## list of path to restrict the user "geographicaly"
#path : ['/home/bla/','/etc']
## set the home folder of your user. If not specified the home_path is set to
## the $HOME environment variable
#home_path : '/home/bla/'
## update the environment variable $PATH of the user
#env_path : ':/usr/local/bin:/usr/sbin'
## allow or forbid the use of scp (set to 1 or 0)
#scp : 1
## allow of forbid the use of sftp (set to 1 or 0)
#sftp : 1
## list of command allowed to execute over ssh (e.g. rsync, rdiff-backup, etc.)
#overssh : ['ls', 'rsync']
## logging strictness. If set to 1, any unknown command is considered as
## forbidden, and user's warning counter is decreased. If set to 0, command is
## considered as unknown, and user is only warned (i.e. *** unknown synthax)
#strict : 1
## force files sent through scp to a specific directory
#scpforce : '/home/bla/uploads/'
If this looks like something you would like to be able to do, you can install it with apt-get:
z@zentury ~$ apt-get install lshell
You can change a current user to have the limited shell with the following command:
sudo chsh -s /usr/bin/lshell backupbot
You can add a new user with a limited shell with the following command (-m creates the home directory):
sudo useradd -m -s /usr/bin/lshell backupbot