Wednesday, February 7, 2018

SCP files thru multiple proxy hosts

I realize this might be old-hat for quite a few but I just learned it and this will save me so bloody much time!

While there are multiple ways of doing this.. including editing your .ssh/config file to include a similar reference I am choosing the full CLI method.

So first off make sure netcat (nc) is installed on all hosts.  Then craft a string as such:

scp -o ProxyCommand="ssh first_host nc second_host 22" /local/path/to/file user@target_host:/dest/path

So what I have done here is to ssh proxy through host1, to host2 then scp'd from host2 to target_host.  Which in my case was exactly what I needed since this new Java environment requires me to jump through two proxies to reach my target.

Like I said I know this is old stuff to a large percentage of you Unix/Linux admins but hopefully this will help someone.

Wednesday, January 31, 2018

Dynamically naming Konsole tabs

So at work I use Fedora 27, and I administer quite a number of Linux servers.. So since I run the Plasma desktop environment (DE) I use the terminal emulator Konsole.  The Konsole window uses tabs.. much like modern internet browsers to help you multitask instead multiple full windows.

So anyway when you open Konsole the opening tab is named with, by default, username and current directory. If you SSH into a remote host the tab name changes to username and remote host.. which is very cool.  However if you further SSH into another host from the first the tab name remains the same as it was.  Which.. for me anyway leads to mass confusion if you have more than a couple tabs open.

So one of the fine folks in teh Fedora User mailing list tossed me a bone today.. I inquired about being able to change the tab name based on remote hostname past the first remote host.  Here's what he gave me:

    chpwd() {
        [[ -t 1 ]] || return
        case $TERM in
            sun-cmd) print -Pn "\e]l%~\e\\"
            *xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;[%m] %~\a"
            vt220) print -Pn "\e]2;[%m] %~\a"


So.. I'll admit that I do not quite understand the % or print syntax as of yet.. however adding this tidbit to the end of my .zshrc file then within Konsole changing the tab and remote tab fields to %w did exactly what I wanted to do and more.
The more part meaning that now my tab names also include the username@hostname but also the full path where I am at currently in that remote host.  Honestly its too much info for a small pane.  But it's a damned fine start!

Friday, January 19, 2018

So it's been a while..

Been quite a while, actually, since my last post. Been busier than ever really, with work and home stuff and doing all I can to get out and enjoy Montana.

Back during the summer and fall I try to get out and hike once a week.. whether its Mt. Helena or just out in the woods around the Wickes mine.   Also got to hunt this year, which is always a good time.  Got my first Montana whitetail this year too! (or well technically last year but yeah)

Driving down an unnamed road, because yeah like I'm going to give out my secret hunting spots.. A truck leaving a driveway had the passenger hanging out of the window pointing up and across the road.  I swivel my head to see this big 8 point standing there looking all majestic like.  So TL;DR I was able to sneak within 50 yards and popped him.  Single shot, through and through lungs. He ran maybe 20 yards and fell. The last day of season, the last 20 minutes of daylight :)

Sadly though I did not get to get him with a new scope I got for christmas:

A no-name Amazon purchase, 6-24x52mm.. you can really reach out and see your target.  Mounted on the Ruger American LH bolt-action in a stainless 30-06 package, it was the All Weather model.  And being perfectly honest, I went for the stainless after seeing Glenn Villenue on Life Below Zero's rifle.

Anyway I do have some pictures to post here from the places I've hiked thus far.. so damn beautiful here.  I love it.

Wednesday, August 30, 2017

DavMail, Thunderbird and Systemd..

So I can't recall if I posted about this or not but since switching full time to Fedora I've had to get creative with email clients.  Since Evolution is clunky and rather ugly I decided to brave the DavMail world with Thunderbird.

Now for quite a while I've been suffering through DavMail just quitting on me.  Nothing gets logged anywhere, the pid just dies. However today in #systemadmins I tossed out a question and it was fielded by a guy who I'd consider quite the senior in the whole *nix/SysAdmin world.  Due took less than 20 minutes and had me a working systemd.service file that will run automagically and restart if it happens to die, oh and get this.. it will LOG too! *giggle*

Here's the file for those interested:

Description=DavMail Exchange Gateway
#ExecStart=/usr/bin/davmail /etc/conf.d/
#ExecStop=killall davmail
ExecStartPre=/usr/bin/bash -c "for i in $BASE/lib/*; do /usr/bin/systemctl set-environment CLASSPATH=${CLASSPATH}:$i ; done"
ExecStart=/usr/bin/java -Xms1G -Xmx1G -Djava.awt.headless=true -XX:ErrorFile=/tmp/davmail_errors.log -XX:-HeapDumpOnOutOfMemoryError -cp ${BASE}/davmail.jar:${CLASSPATH} davmail.DavGateway ${PROPERTIES}

Wednesday, July 26, 2017

Python 3 + Paramiko UPDATE

I can hear the voice over from Unreal Tournament. back in the day, "MU MU MU MULTIKILL!"

I figured out the correct syntax for my SSH/paramiko script thus completing my second actual Python script.  WOOT. (With vast amounts of help from the guys in an IRC channel I frequent)

So my hangup on all of this boiled down to trying to use a Python2 command in Python3.. Ok well two instances of that: raw_input() was changed to just input().  And my print stdout() should have been print(
Once I got those values changed she ran like a well-oiled machine.  Here's what I've been working on:

import sys, paramiko, getpass

user = input("Username:") #Prompts for username#passwd = getpass.
getpass("Password for " + user + ":") #Prompts for password
key_file = input("Publickey full path:") #Prompts for full path to 
key file
name = input("Target Hostname:") #Prompt for target 
command = input("Enter target command:") #Prompt for 
remote command

#Calling the paramiko ssh function
ssh = paramiko.SSHClient() 
#Define value 'ssh' as calling the paramiko.sshclient
print('calling paramiko')ssh.set_missing_host_key_policy(paramiko.
AutoAddPolicy()) #Must come before connect line to add hosts 
to known_hosts#ssh.connect("name", username="user",
ssh.connect(hostname = name, username = user, key_filename = 
key_file) # key_filename means to specify, 
pkey on the#other hand means to actually paste in the key text 
print('trying to connect')
stdin, stdout, stderr = ssh.exec_command (command)

I will keep this, if anything as a paramiko snippet.  It works, it shows me how to SSH into a remote host and run a command.  At this early stage, I can't ask for much more.