Nokia N900 – Maemo

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

 

Source Maemo.Org