LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-28-2008, 01:10 PM   #1
markdjones82
LQ Newbie
 
Registered: Nov 2004
Location: Dallas
Distribution: Suse 9.1
Posts: 15

Rep: Reputation: 0
Running remote sed


Hey all, I am trying to run a remote command to replace text in my sshd_config file. I want to be able to run it remotely to all of the servers I have. How would I run this sed command remotely? so far I have


ssh server 'sed -i 's/#PubkeyAuthentication/PubkeyAuthentication/g/' sshd_config'


Doesn't seem to want to work. Any help?


Eventually i want to be able to pull in a text file with all of the server names
 
Old 10-28-2008, 01:29 PM   #2
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
ssh root@<server> "/bin/sed -e 's/#PubkeyAuthentication/PubkeyAuthentication/' /etc/ssh/sshd_config'>/etc/ssh/sshd_config1 && mv /etc/ssh/sshd_config1 /etc/ssh/sshd_config"

(one line) should do
 
Old 10-28-2008, 01:40 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Use a full path to the config file: /etc/ssh/sshd_config.

You need to login as root to do this. It isn't a good idea to allow root logins, especially if you use password authentication. I imagine that is what you are trying to fix.

Also consider:
UsePam yes
PermitRootLogin no
PubkeyAuthentication yes
ChallengeResponseAuthentication no

See the comments for "UsePam" in the /etc/ssh/sshd_config file. These settings only allow pubkey authentication and use PAM for session control. Another entry to consider is "AllowUsers" to only allow logins from certain users. The entries can also use the "user@host" form, which allows logins for (local)user @ (remote)host. Further info is in the ssh_config manpage.

You may need another sed command in the sed line. You can add sed commands in a oneliner by separating them with ";" or using the -e option before each command.

Last edited by jschiwal; 10-28-2008 at 01:52 PM.
 
Old 10-28-2008, 01:50 PM   #4
markdjones82
LQ Newbie
 
Registered: Nov 2004
Location: Dallas
Distribution: Suse 9.1
Posts: 15

Original Poster
Rep: Reputation: 0
I actually had the full path to the ssh file. I will look at it again with the above suggestions thanks.



ssh root@<server> "/bin/sed -e 's/#PubkeyAuthentication/PubkeyAuthentication/' /etc/ssh/sshd_config'>/etc/ssh/sshd_config1 && mv /etc/ssh/sshd_config1 /etc/ssh/sshd_config"

This worked except I had to remove the one ' after sshd_config. Now how come I have to export it to another file and then move it? Why wouldn't just the command alone replace it like it does if ran locally?

Last edited by markdjones82; 10-28-2008 at 01:59 PM.
 
Old 10-28-2008, 02:08 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The "-i" sed option will allow you to do in situ editing, so you don't need to redirect to a temporary file. The example given in #2 didn't use "-i". I'm not sure if "-i" is portable.
\

Last edited by jschiwal; 10-28-2008 at 07:57 PM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running remote X application - help n03x3c Linux - Newbie 5 09-08-2008 11:36 PM
running sed inside script file bajaj111 Linux - Software 9 11-08-2006 09:23 AM
need help running remote X applications zero79 Debian 5 06-11-2005 09:55 PM
running KDE from remote hamza11050 Linux - Software 7 02-13-2005 08:54 PM
remote job running apiav Slackware 4 05-27-2004 08:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:29 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
Open Source Consulting | Domain Registration