Archive for the ‘unix’ tag
Using screen
My work setup is like this: I have two monitors, one for a maximized Thunderbird window, and the other for a PuTTY window, Firefox, Outlook (minimized to tray, and only used for calendar reminders mostly), and IE. Well, I do open other windows, but I tend to use the above most often.
I use PuTTY extensively to manage remote Unix systems. I also like my desktop uncluttered, so instead of multiple PuTTY windows, I only use one. I log on to a “jump” host, fire up `screen`, and I’m all set.
At home, I have a similar setup. Below is my .screenrc:
# Default sessions screen -t MISC 4 screen -t EVEY 4 screen -t INES 3 screen -t IANDEXTER_COM 2 screen -t IANDEXTER_NET 1 screen -t HOME 0 # Scrolling buffer defscrollback 99999 altscreen on # PuTTY fix term xterm termcapinfo xterm ti@:te@ # Status line hardstatus alwayslastline hardstatus string '%{= kG}%-Lw%{= bW}%50> %n %t %{= kG}%+Lw%< ' # Key bindings bindkey -k k6 detach bindkey -k k7 quit bindkey -k k8 hardstatus alwayslastline bindkey -k k9 hardstatus alwaysignore # Other stuff startup_message off autodetach on defutf8 on crlf off setenv LC_CTYPE en_US.UTF-8
The Default sessions section opens up windows for my other hosts (guess how I name my boxes ;)). I also have a pretty large scroll buffer — useful when tailing logs. The hardstatus lines show the sessions and highlights the active one. I got the (not-so) fancy-schmancy color codes from here. Lastly, I bind the F6 to F9 keys to, respectively, detach the screen session, quit screen, toggle off the status line, and put it back on.
My .screenrc at work is more or less the same, except for the sessions I open. I can also tellscreen to use a different shell (I’m an unabashedly Bash fan, heh) apart from what is default in the systems I manage.
Quick directory switching
At work, I do a lot of directory traversal: going from one location to another within the whole (global) filesystem structure. So, to conveniently go back to a previous directory, I use pushd and popd, aside from the usual cd:
$ pwd /home/iandexter $ pushd /etc/sysconfig $ pwd /etc/sysconfig $ popd $ pwd /home/iandexter
You can even echo $DIRSTACK to list the current directories in the stack, and push multiple directories.
Quickies
- Work: Gone Unix-hardcore. Our team currently leads Unix training for other infra teams. Shell/Perl scripting occupies a large part of the, er, curriculum. I’m “re-learning” Perl. I’m also amazed as to how open source is being leveraged here. I lurve open source.
- Family: Prior to a change of shift sked, I go on an extended off-shift period of four days. Like, wow! What better way to start that four-day weekend than to slooowly fry in my own oil (not a nice imagery there) here at the airport. Hooray. Love the company, though, as always.
- Others: I still haven’t gotten around to reading Good Omens. Haven’t watched Harry Potter, too. (Why bother? I heard it’s not as good as the book, anyway.) And, I haven’t been online in a while. Smart 3G’s a big bummer. Been getting lots of connection errors lately. Hope it stabilise soon.
Long night
I’m still here at the office, watching text scroll down (or is it up?) the monitor. Actually, I’m backing up the whole /var partition from one of the mail servers, to make way for a larger capacity disk.
You’re thinking, duh, LVM. But this server had been set up way before LVM became stable. I could not even back up to tape — not yet, at least — because I have to get this up and fast, while keeping the server live, so I’m doing it over (of all things) USB, and 1.1 at that.
(Heh, fast. I’ve been at it since 5 PM, and I’m not nearly halfway done. *sigh* Such is life.)
Windows-to-*nix public key authentication
I’ve worked with lots of servers, most of which I cannot access directly, so I often use remote access: Remote Desktop Connection or Terminal Services in Windows, and ssh in *nix.
While I do have PasswordSafe to remember all those passwords, I’m the lazy admin type, so I often opt for password-less authentication using public keys. For this, I use PuTTY, et. al.
- First, I generate an RSA key using PuTTYgen. I don’t enter anything for the passphrase. Warning: NOT recommended for production servers!
- I save the public and secret keys (in .PPK format) in a directory. I also cut and paste the RSA string in a text file,
key.txt. - For now, the remote box is configured for “normal” ssh, that is, through password authentication. So, I copy over the RSA string file to the remote box:
C:\> pscp \path\to\key.txt user@remote-host:/home/user/.
- I also edit the SSHd config file,
/etc/ssh/sshd_config, with the following parameters:RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys PasswordAuthentication no PermitRootLogin no
- SSHd is then restarted.
- Back in Windows, I launch PuTTY, and enter the host name for the remote box. In the SSH/Auth category, I place the private key file saved earlier. I save the session, named
remote-nopass. - I then launch Pageant, drill down to Saved Sessions > remote-nopass. It will bring up the SSH login page, where I enter my login name, after which, I am authorized through the pubkey, and log in to the SSH session.
$ mkdir .ssh $ mv key.txt .ssh/authorized_keys $ chmod 700 .ssh; chmod 600 .ssh/authorized_keys
Seems tedious at first, but I can then export key.txt to other remote servers, and just save sessions for Pageant’s use. Pageant is conveniently located in the system tray within reach.
