sed replace #PermitRootLogin yes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed replace #PermitRootLogin yes
# 1  
Old 01-06-2010
sed replace #PermitRootLogin yes

I can't seem to get this to work. I am trying this:

sed -e 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config

I am not super familiar with sed. Any help?
# 2  
Old 01-06-2010
Hi.

This won't update the file, if your sed supports it, use sed -i

Otherwise you can use ed.

Code:
ed /etc/ssh/sshd_config << !
,s/#PermitRootLogin yes/PermitRootLogin no/
w
q
!

(someone will also, probably give you a nice Perl one-liner...)

Is commenting out PermitRootLogin yes not the same as an uncommented PermitRootLogin no anyway?
# 3  
Old 01-06-2010
No, it is not the same because that is the default in SSHD_config

Also, I know that command won't update the file, but it doesn't even replace it in the output. I would end up using -i to actually replace it, but I am looking at the output.

I need it to uncomment and then replace the yes with a no.
# 4  
Old 01-06-2010
Then perhaps the expression you are using does not match the content in the file.
# 5  
Old 01-06-2010
Quote:
Originally Posted by scottn
Then perhaps the expression you are using does not match the content in the file.
It does matchup, I just dont' think the sed command is working right.

Here part of the file:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

Your ed command did work, but I'd liek to get it working with sed so I can add it to a bash script if possible.
# 6  
Old 01-06-2010
I know that in sed you can have comments using #. My sed supports this too, but it doesn't cause any problem with the substitution.

Does it make any difference if you escape the # (i.e. like \#)?

Otherwise, perhaps your input file has a hidden or control character somewhere?

Last edited by Scott; 01-06-2010 at 05:53 PM..
# 7  
Old 01-11-2010
Quote:
Originally Posted by scottn
I know that in sed you can have comments using #. My sed supports this too, but it doesn't cause any problem with the substitution.

Does it make any difference if you escape the # (i.e. like \#)?

Otherwise, perhaps your input file has a hidden or control character somewhere?
Sorry for the delayed response. I will try the escape. In theory my command up in the first post should work right?

I am running RHEL 5.3 so it should have a recent version of sed. I will try the results tomorrow!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed Replace

I have a file whose output words are always like this: aaaa bbbb cccc dddd. Trying to arrange the data so that there are 2 columns such that the 1st word become the 1st column like this: aaaa aaaa aaaa bbbb aaaa cccc aaaa dddd Trying to use awk... (8 Replies)
Discussion started by: jimmyf
8 Replies

2. Shell Programming and Scripting

Sed/replace help

How can we empty or replace with null, following block of code (within the php quotes including the quotes) from inside a file. *** some other data above this code <? #317008# ... (5 Replies)
Discussion started by: fed.linuxgossip
5 Replies

3. Shell Programming and Scripting

sed replace

Hi, i have a file as give below >cat sample_file param1 val1 2012-06-19 ##there can be one or more space after 2012-06-19 in the above file i want to replace val1 with a with value passed through a variable... below is the command i tried >parval='param1 val2' >par1=param1 >sed... (3 Replies)
Discussion started by: midhun19
3 Replies

4. UNIX for Dummies Questions & Answers

sed - replace

i want to replace: /abc/123/script with /abc/scripts i tried sed -e 's///g' but did not work. Please use code tags <- click the link! (2 Replies)
Discussion started by: lawsongeek
2 Replies

5. Shell Programming and Scripting

Sed help with replace

phx,v3apilw2core,app-usage,05-03-2010, phx,tr(white,wavern), 2,1 I need help with the sed command to remove the text in red from the line above, including braces. I tried the following two approaches:- sed '/(/,/)/ !d' test.txt | more sed "/(/,/)/ !d" test.txt | more (1 Reply)
Discussion started by: smee
1 Replies

6. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

7. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

8. Solaris

Solaris 8 PermitRootLogin

Hi All, The file /usr/local/etc/sshd_config have no lines about PermitRootLogin yes or PermitRootLgoin no What does it mean? No login for root or it does. Thanks in advance. :) (5 Replies)
Discussion started by: itik
5 Replies

9. Shell Programming and Scripting

using sed to replace ' with `

Dear All, I am writting a shell script program on AIX server version 5.3 in which I am doing cleaningprocess for files in which I am trying to replace ' with ` . and for this I am using following command: sed -e 's//$/g' -e 's/\\/\//g' -e 's/'/`/g' $file >>... (2 Replies)
Discussion started by: mr_dba01
2 Replies

10. Shell Programming and Scripting

How to replace using SED?

Hi, I want to change a particular string in a file with another string. This is part of a larger script file. I m using SED for this purpose: sed -e 's/hostname.domainname/${HOST}.${DOMAIN}/g' $sed_file>$tmp_file Where the occurance hostname.domainname has to be replaced with the... (4 Replies)
Discussion started by: mahatma
4 Replies
Login or Register to Ask a Question