lsof -i tcp:22 | grep 192.168.10.10 | awk "{print $2}" |xargs kill

This will kill all ssh connections from a given host it does give some errors but it does work

you could redirect output to /dev/NULL

0
By: gda2004
2012-05-10 10:45:22

These Might Interest You

  • This is an attempt to get a command which I can alias. It's ugly but it works. I'm hoping someone can suggest a cleaner version. I have tried.... # alias kfire="for i in $( ps aux | grep [F]irefox | awk \'{print $2}\' ); do kill $; done" # alias kfire=`kill $(ps aux | grep [F]irefox | awk '{print $2}' | tr '\n' ' ')` # alias kfire='ps au | grep -i [F]irefox | awk \'{ print $2 \'} ' and they all fail in a .bashrc I've tried escaping the quotes and can't find a way to make the single quotes ' that awk wants work. Maybe I'm just stubborn but I don't want to put in a little #!/bin/bash file just so I can kill a firefox process all in one stroke. This script works (it kills the process before it errors out)... it's just ugly and there may be a pretty way to do this. Show Sample Output


    -2
    alias kfire='for i in `ps aux | grep [F]irefox `; do echo $i; kill $(($i)); done; '
    swerve · 2010-12-27 01:47:58 4
  • This will probably kill any user sessions and/or ssh connections to other servers you might have active.


    5
    pkill -u `whoami`
    seattlegaucho · 2010-11-15 18:42:29 0
  • This command will kill all processes using a directory. It's quick and dirty. One may also use a -9 with kill in case regular kill doesn't work. This is useful if one needs to umount a directory. Show Sample Output


    4
    lsof|grep /somemount/| awk '{print $2}'|xargs kill
    archlich · 2009-03-12 18:42:19 3
  • If you are behind a restrictive proxy/firewall that blocks port 22 connections but allows SSL on 443 (like most do) then you can still push changes to your github repository. Your .ssh/config file should contain: Host * ForwardX11 no TCPKeepAlive yes ProtocolKeepAlives 30 ProxyCommand /usr/local/bin/proxytunnel -v -p -d %h:443 Host User git Hostname ssh.github.com ChallengeResponseAuthentication yes IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Basically proxytunnel "tunnels" your ssh connection through port 443. You could also use corkscrew or some other tunneling program that is available in your distro's repository. PS: I generally use "github.com" as the SSH-HOST so that urls of the kind git@github.com:USER/REPO.git work transparently :) You


    3
    git remote add origin git@SSH-HOST:<USER>/<REPOSITORY>.git
    jnash · 2009-11-19 06:57:50 1
  • Searches /var/log/secure for smtp connections then lists these by number of connections made and hosts.


    -2
    cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
    empulse · 2009-03-30 15:49:54 2
  • Forward connections to $HOSTNAME:8080 out to $HOST:80


    -2
    ssh -g -L 8080:localhost:80 root@$HOST
    kayowas · 2009-10-24 20:56:00 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: