Archive for November 2nd, 2012

How to Share virtual terminal SSH between mutliple logged in users with screen / Create multi user sessions with GNU screen

Friday, November 2nd, 2012

How to share bash shell between multiple users with gnu screen - share virtual terminal via ssh through multiple users screen

GNU Screen is great utility with a number of helpful features. Maybe there is no UNIX / (GNU / Linux),  admin which doesn't use screen or some similar terminal emulator prog. daily basis.

Little might know however abut a kewl functionality allowing, a few logged in users via ssh to share one terminal.

Sharing a virtual terminal with another person, is very helpful if you want to teach someone a bit of Linux / UNIX basics, showing him how certain commands works on a system etc. etc.

Shared terminal session is very helpful in case of need for remote system administration or support, whether instead of explaining someone over the phone for 20 minutes or an hour a bunch of commands he has to run to achieve something,  you can login share terminal with screen and do whatever necessary  in front of his eyes.

Shared screen session, can actually in theory allow unlimited people to watch what a certain one is doing in a his virtual terminal. This is very helpful for example in Computer Laboratories for Teachers to teach students FreeBSD, Linux, bash, csh shell scripting, perl or whatever programming language taught.

Allowing two or more logged in users with same user credentialsto use screen can be done pretty easy, one primary user (creating the initial screen terminal session), should just launch GNU screen:

test@noah:~$ screen

The second, third, 4th, 5th and the rest of users should login via SSH session with same user, lets say test and launch screen -x

test@noah:~$ screen -list
There is a screen on:
    20147.pts-5.noah    ( 1.11.2012 18,27,50)    (Attached)
1 Socket in /var/run/screen/S-hipo.

 

test@noah:~$ screen -x

I'm not sure if screen has some kind of limitation on how many users maximum can connect to a screen session, but I guess it should be high enough for dozen of people –  at least 512 or 1024 people to connect and share one shell simultaneously.

In some Linux distributions (versions) RHEL, CentOS it is possible screen -x not to work out of the box, because screen binary is not set to be SUID.
On latest Debian versions and deb derivatives thanksfully, screen bin is by default installed as SUID so screen -x works fine.

hipo@noah:~$ ls -al /usr/bin/screen
-rwxr-sr-x 1 root utmp 364088 29 юли  2009 /usr/bin/screen

Enabling mutiuser screen login via a running screen session is possible by pressing:

CTRL + a + : and typing in prompt  multiuser on

In case you want to have a system user which by default allows a multiple logged in users to share shell you can use a little 'hack' just change in /etc/passwd the field recordfor user shell (/bin/bash) with (/usr/bin/screen)

Lets say you want to allow the user test support multiple logged in users share one shell the record for test in /etc/passwd should look smth. like:

test:x:1003:1004:,,,:/home/test:/bin/bash

Change it with your favourite text editor to:

test:x:1003:1004:,,,:/home/test:/usr/bin/screen

If you have some problems running screen, check permissions and eventually exec as superuser:

chmod u+s /usr/bin/screen


How to find how much power (electricity) consumption a server or PC has?

Friday, November 2nd, 2012

Kill-A-Watt track system power electricty consumption on GNU / Linux servers and FreeBSD
A friend of mine today ask me if I have clue if it is possible to track his home computer Consumption with some piece of Software?

The question is quite interesting, since I run a home server with Linux and it would have been nice if I can exactly track how much electricity per month it  consumes

Now knowing, the answer I first checked online for some kind of software and all I can find something that does something similar but all can find is powertop.

Though powertop is nice Linux tool to keep an eye which program on PC consumes most from overall consumed electricity and order the programs and modules based on electricity consumption it is not providing information on overall electricity consumption.

As the topic seem to be some interesting, I've decided to ask in irc.freenode.net #deiban
Here is a paste from  irssi channel log:

17:21 < hipodilski> hi any idea, how can I find how much electricity a server conmuses per month
17:21 < hipodilski> is there some some kind of software
17:21 -!- digdilem [~digdilem@plague.digdilem.org] has joined #debian
17:22 < babilen> hipodilski: I would recommend an electricity meter rather than software
17:22 -!- tommy_e [~tommy@81.27.221.202] has quit [Ping timeout: 260 seconds]
17:22 < jelly-home> watt meters ftw
17:22 -!- msx [~msx@190.194.114.10] has joined #debian
17:22 -!- blackshirt [~najwa@103.3.223.5] has left #debian []
17:23 < hipodilski> yes but i don't have electricity metter, if there is software it would be interesting to try it
17:23 -!- badiane [~gdurand@D8FF67fa.cst.lightpath.net] has quit [Remote host closed the connection]
17:23 < xand> hipodilski: no, you need a hardware device.
17:23 < jelly-home> now everything can be solved in software, hipodilski
17:23 < jelly-home> not*
17:23 < jelly-home> dammit
17:23 < xand> unless you have a very fancy PSU, software can't find that out
17:23 < babilen> jelly-home: hehe, nice typo !
17:23 < vacuous> hipodilski yes
17:24 < HelloShitty> nsadmin, are you out of ideas for me?
17:24 < vacuous> there's various devices that do it
17:24 -!- firecode [~irc@unaffiliated/firecode] has joined #debian
17:24 < vacuous> you can either get a killawat which are highly innacurate but it might give you a clue
17:24 < vacuous> and they're very cheap too
17:25 < vacuous> you can get a device which measures your entire houses electric, then you just turn off all the appliances and run the
                 server only
17:25 -!- trysten [~trysten@37-251-103-145.FTTH.ispfabriek.nl] has quit [Quit: be back]
17:25  * babilen likes that approach
17:25 < babilen> But this is getting a bit too off-topic. Maybe hipodilski wants to take it to #debian-offtopic
17:25 < vacuous> or you can keep all fridges on, check what the reading is and then negate that from the total
17:25 < hipodilski> yes thanks 🙂
 

The answer makes it clear right of time of writing this post there is no software for Linux or BSD that keeps track electricity consumption daily or monthly

I've googled to see what is Kill-A-Watt hardware? and found fuzzy named device Kill-A-Watt for sale on ThinkGeek's website for the not so expensive 24.99$

To use Kill-A-Watt device is to be connected inside the power plug and then PC or Server has to be plugged into  Kill-A-Watt dev. I've red also (while researching) many Intelligent UPS devs has support for keeping log of discharged energy, so just buying a good UPS with web administrator or even a cheap one providing statistical information of UPS use via serial port should be another alternative to track ur server consumption.