LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2012, 10:39 PM   #1
federico101
LQ Newbie
 
Registered: Sep 2012
Posts: 1

Rep: Reputation: Disabled
how to ssh multiple ips


We use linux mint at my school and every friday we play something called hacker survivor.Where we have to shut off computers thru ssh we use the command ssh (ip address) but i wanted to know if there was anyway to shutdown multiple ips with that command.Im new to linux so sorry if thats a noob question.
 
Old 09-23-2012, 05:13 AM   #2
heinblöd
Member
 
Registered: May 2004
Location: France
Distribution: Slackware Gentoo
Posts: 186

Rep: Reputation: 31
ssh means Secure Shell and does nothing than opening a session on a remote computer.

So if you use ssh to shut off a computer, you would type 'ssh IP' , give username and password and the maybe type a command to poweroff a computer .

This can only be done on one computer at a time as it is NOT ssh which powers down the box, but a command on that box to halt,reboot etc it

Last edited by heinblöd; 09-23-2012 at 05:14 AM.
 
Old 09-23-2012, 12:51 PM   #3
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,970
Blog Entries: 11

Rep: Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166
stick the IPs only of the machines you want to shutdown in a file (one IP per line), say /tmp/hsshutdown.hosts
save and exit the file you just edited and run in terminal
Code:
for i in `cat /tmp/hsshutdown.hosts` ; do ssh root@$i halt ; done
Other more elegant solutions may also be offered and there are certainly as many ways to accomplish this task as there are Linux SysAdmins.

Last edited by Habitual; 09-24-2012 at 07:00 AM.
 
Old 09-23-2012, 03:22 PM   #4
heinblöd
Member
 
Registered: May 2004
Location: France
Distribution: Slackware Gentoo
Posts: 186

Rep: Reputation: 31
Quote:
Originally Posted by Habitual View Post
stick the IPs only of the machines you want to shutdown in a file, say /tmp/hsshutdown.hosts
save and exit the file you just edited and run in terminal
This would work, but only if you use a certificate based authentification.
Any ssh connection which requires a password, would wait for the user input before going on to the second host.
As far as I know, ssh does not accept the password as a commandline switch.
 
Old 09-23-2012, 08:19 PM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,970
Blog Entries: 11

Rep: Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166Reputation: 2166
Quote:
Originally Posted by heinblöd View Post
This would work, but only if you use a certificate based authentification.
Any ssh connection which requires a password, would wait for the user input before going on to the second host.
As far as I know, ssh does not accept the password as a commandline switch.
Man says "Finally, if other authentication methods fail, ssh prompts the user for a password."

ah, my code assumes the use of ssh keys. I am a big dummy sometimes.

Last edited by Habitual; 09-23-2012 at 08:20 PM.
 
Old 09-23-2012, 09:06 PM   #6
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,445

Rep: Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794Reputation: 1794
If the environment is not erased each week then keys could be planted on all machines gradually? I've done similar in a computer lab, planting files on each machine I sat at.
Heck, plant a remote-shutdown script the day before?
Otherwise, if you've got root then kill sshd?
If not then disconnect the network cable while you prepare your attack?
Then there's the "hardware hack" of plugging another keyboard into the machine and using that to shut it down -- mots are USB now and even those using PS/2 tend to accept USB also so you can connect another keyboard and hide the cable (or use a wireless one).
 
Old 09-24-2012, 02:43 AM   #7
heinblöd
Member
 
Registered: May 2004
Location: France
Distribution: Slackware Gentoo
Posts: 186

Rep: Reputation: 31
Quote:
Originally Posted by Habitual View Post
Man says "Finally, if other authentication methods fail, ssh prompts the user for a password."

ah, my code assumes the use of ssh keys. I am a big dummy sometimes.
Don't get me wrong, I wanted to say that your code will be fine as long as you don't need to type in passwords .

If the host only accepts passwords (or you don't have the public key) it may work when using some
heredoc construction like
Code:
ssh x.x.x.x <<HEREDOC
password1
password2
HEREDOC  poweroff
I have not tested it , only an idea
 
Old 09-24-2012, 03:12 AM   #8
heinblöd
Member
 
Registered: May 2004
Location: France
Distribution: Slackware Gentoo
Posts: 186

Rep: Reputation: 31
Quote:
Originally Posted by 273 View Post
Then there's the "hardware hack" ...
Pull the power plug?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH tunneling with multiple IPs? N4melessS0ldier Linux - Networking 13 09-03-2010 03:28 AM
SSH tunneling on multiple ips jollibeey Linux - Security 1 08-19-2009 02:42 AM
Getting things straight: Apache, SSL, Multiple External IPs / Internal IPs robin.com.au Linux - Server 21 10-13-2007 11:39 PM
SSH tunneling with multiple IPs phoinix Linux - Networking 2 03-27-2007 01:09 PM
how to define a specific range of IPs and/or multiple IPs in an iptables rule?... TheHellsMaster Linux - Security 9 09-20-2004 10:06 AM


All times are GMT -5. The time now is 01:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration