Have a look at simulating keyevents on Android and search for "KEYCODE_VOLUME_UP" and "KEYCODE_VOLUME_DOWN".
Events can be generated by executing "input":
#local shell:
input keyevent 24 #vol up
input keyevent 25 #vol down
#remotely using ssh
ssh your-phone input keyevent 24 #vol up
ssh your-phone input keyevent 25 #vol down
# 'su -c command' to make it run as root (if not already). EDIT: now escaped properly.
ssh your-phone su -c "input\ keyevent\ 24" #vol up
ssh your-phone su -c "input\ keyevent\ 25" #vol down"
Your shell needs appropriate permissions most probably to fire input events I guess. If you do public key authentication and keep your private key loaded in memory (ssh-add) you can make a wrapper script and just execute this without beeing asked for a passphrase. Note: There's a considerable overhead for both 'su' and 'input', all in all one single volume adjust takes 2.5s to complete on my HTC Desire.
EDIT2:
shell@android:/ $ id
uid=2000(shell) gid=2000(shell) groups=1003(graphics),1004(input),[...]
shell@android:/ $ time input keyevent 24
0m0.92s real 0m0.29s user 0m0.06s system
Seems like you have to be member of the input group (here GID=2004) to have the capability to generate keyevents using 'input'. Also, I noticed that the screen has to not be locked (and/or off), because the lock would consume all keyevents eventually. Note also that the command takes almost 1 second.