Results 1 to 3 of 3
What I am trying to achive is the editing of /etc/ssh/sshd_config
I have the line
Code:
AllowUsers usera userb
And I want to be able to append to the end ...
- 01-29-2011 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
sed append to end of a specific line
What I am trying to achive is the editing of /etc/ssh/sshd_config
I have the line
And I want to be able to append to the end of this line from a bash script.Code:AllowUsers usera userb
I have muddled together from other sites and got the following:-
But this appears to add userc directly after AllowUsers and not after userbCode:sed -e "s/^AllowUsers/\0 userc/" -i /etc/ssh/sshd_config
I'm not great with sed so it's proably something simple.
Thanks in advance
- 01-29-2011 #2Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
Ok have found the solution:-
Seems to work for me.Code:sed -e '/AllowUsers/s/$/ userc/' -i /etc/ssh/sshd_config
- 01-31-2011 #3
I don't think a further reader would understand that (it took me some time to figure this out) and you could rewrite this to:
I use here backreferences to make it more clear what the expression does and use piping to make it clear that this command also writes to the file. One could drive it further and parse each single username that is already configured by means of a sed subroutine.Code:sed -e '/AllowUsers/s/AllowUsers\(.*\)$/AllowUsers\1 newuser/g' test > test
Thus you could add and remove users invoking this command only.Code:sed -e '/AllowUsers/s/AllowUsers\({...}\)$/AllowUsers\1 newuser/g' test > test


Reply With Quote