Active Topics

 


Reply
Thread Tools
Posts: 48 | Thanked: 32 times | Joined on Dec 2010 @ Russia, Moscow
#1
This is a dirty workaround, but no one seems to find a more elegant way.

Put these lines in your /etc/ssh/sshd_config
Code:
Compression no #optional
UseDNS no #optional
ForceCommand /usr/lib/openssh/ssh-session
Create /usr/lib/openssh/ssh-session
Code:
#!/bin/sh

if [ $USER = root ]; then
  IFCONFIG=ifconfig
  MGMT=/usr/lib/openssh/ssh-power-management
else
  IFCONFIG="sudo ifconfig"
  MGMT="sudo /usr/lib/openssh/ssh-power-management"
fi

WLAN_IP=$($IFCONFIG wlan0 | sed -n 's/.*inet addr:\([0-9.]\+\).*/\1/p')
SSH_IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 3)

if [ "$WLAN_IP" = "$SSH_IP" ]; then
  ps -f | grep /usr/lib/openssh/ssh-power-management | grep -qv grep
  if [ $? -eq 1 ]; then
    $MGMT &
  fi
fi

if [ -n "$SSH_ORIGINAL_COMMAND" ]; then
  eval $SSH_ORIGINAL_COMMAND
else
  $SHELL
fi
Create /usr/lib/openssh/ssh-power-management
Code:
#!/bin/sh

if [ $USER = root ]; then
  IWCONFIG="iwconfig"
else
  IWCONFIG="sudo iwconfig"
fi

while [ $(lsof -a -i4 -a -i :ssh | grep ESTABLISHED | wc -l) -gt 0 ]; do
  $IWCONFIG wlan0 power off
  $IWCONFIG wlan0 txpower 100mW
  sleep 20
done

$IWCONFIG wlan0 power on
$IWCONFIG wlan0 txpower 10mW
You need to have wireless-tools installed (and sudser if you don't want to add an appropriate entry to /etc/sudoers.d/).

Then run
Code:
sudo chmod +x /usr/lib/openssh/ssh-session
sudo chmod +x /usr/lib/openssh/ssh-power-management
sudo /etc/init.d/ssh restart
Authentication process will remain slow and you'll notice a small gap after login; then the lags will disappear until you close all active ssh/sftp connections.
The 20 seconds timeout for invoking iwconfig isn't meant to be precise, test and report your measures.

---------------------------

If you use ssh server only at home, you may also want to do this:

Create /etc/network/if-up.d/ssh (replace YOUR_AP_ESSID with the name of your access point)
Code:
#!/bin/sh

if [ "$ICD_CONNECTION_TYPE" = "WLAN_INFRA" ] ; then
        KEY="/system/osso/connectivity/IAP/$ICD_CONNECTION_ID/name"
        AP=$(/usr/bin/gconftool -g "$KEY")
        if [ "$AP" = "YOUR_AP_ESSID" ] ; then
                /etc/init.d/ssh start
        fi
fi

exit 0
and /etc/network/if-down.d/ssh
Code:
#!/bin/sh

/etc/init.d/ssh stop

exit 0
Comment out the corresponding lines in /etc/event.d/sshd
Code:
#start on stopped rcS

console output

#respawn

pre-start script
    if [ ! -d /var/run/sshd ] ; then
        mkdir /var/run/sshd
        chmod 755 /var/run/sshd
    fi
end script

exec /usr/sbin/sshd -D
Then run
Code:
sudo chmod +x /etc/network/if-*.d/ssh
sudo update-rc.d -f ssh remove

Last edited by Bad_Habit; 2011-12-06 at 13:26.
 

The Following 9 Users Say Thank You to Bad_Habit For This Useful Post:
Posts: 28 | Thanked: 17 times | Joined on Feb 2011 @ Barbados
#2
did this followed your steps now i cant apt-get anything FAPMAN or APPMAN dont work

i even uninstalled openssh

thanx alot! now i gotta reflash

Last edited by T4UR14N; 2011-12-15 at 19:25.
 
Posts: 19 | Thanked: 9 times | Joined on Jun 2011
#3
Originally Posted by T4UR14N View Post
did this followed your steps now i cant apt-get anything FAPMAN or APPMAN dont work

i even uninstalled openssh

thanx alot! now i gotta reflash
It works fine for me. thanks Bad_Habit!

But T4UR14N, whatever your problem is, it has nothing to do with what was posted: there is nothing there that interacts with apt.

Possibly you put a horrendous typo into something in /etc/network/if-up.d/ and now you cant get a net connection??

You could avoid these sorts of problems generally by not duplicating other peoples' operating system modifications until you can reasonably understand what those changes are.
Commands that start with "sudo", or that modify files in /etc or /usr should sound off warning bells in your head.
On the other hand, breaking your linux system can be a great way to learn about it -- just understand that when you do, it will be your own fault!!

(These steps can be mostly undone by just doing them in reverse, that is, remove the 4 NEW files that you created,
Then to fix sshd, remove the 2 new # marks from /etc/event.d/sshd, and get rid of any lines added to /etc/ssh/sshd_config,
then the knowledgeable or brave soul would have to do
sudo update-rc.d -f ssh defaults)
 
Posts: 28 | Thanked: 17 times | Joined on Feb 2011 @ Barbados
#4
Originally Posted by octagonhead View Post
It works fine for me. thanks Bad_Habit!

But T4UR14N, whatever your problem is, it has nothing to do with what was posted: there is nothing there that interacts with apt.

Possibly you put a horrendous typo into something in /etc/network/if-up.d/ and now you cant get a net connection??

You could avoid these sorts of problems generally by not duplicating other peoples' operating system modifications until you can reasonably understand what those changes are.
Commands that start with "sudo", or that modify files in /etc or /usr should sound off warning bells in your head.
On the other hand, breaking your linux system can be a great way to learn about it -- just understand that when you do, it will be your own fault!!

(These steps can be mostly undone by just doing them in reverse, that is, remove the 4 NEW files that you created,
Then to fix sshd, remove the 2 new # marks from /etc/event.d/sshd, and get rid of any lines added to /etc/ssh/sshd_config,
then the knowledgeable or brave soul would have to do
sudo update-rc.d -f ssh defaults)

thanks but this is where backup menu comes in handy
 
Posts: 48 | Thanked: 32 times | Joined on Dec 2010 @ Russia, Moscow
#5
Originally Posted by T4UR14N View Post
thanks but this is where backup menu comes in handy
That's no Unix way, you'd better install syslogd & klogd (using usb to transfer debs) and check out /var/log/syslog - debugging your system is the only way to forget BackupMenu
 
Reply


 
Forum Jump


All times are GMT. The time now is 16:14.