如何在Linux授权文件中的特定单词上附加一些服务器的额外别名

如何在Linux授权文件中的特定单词上附加一些服务器的额外别名

在具有一些定义的字段服务器的授权文件中,但它们可能逐行不同。我想做的就是在该行的特定字段上添加额外的别名。

需要在 ip( 156.154.18.6) 地址后添加以下额外别名:

|ser6.nam.net|156.154.18.7|ser7.nam.net|156.154.18.8

之前的授权文件:

Keys [email protected]
Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser1.nam.net|156.154.12.1"

Keys [email protected]
Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser2.nam.net|156.154.15.2|ser5.nam.net|156.154.18.6"

keys [email protected]

Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser3.nam.net|156.154.17.4|ser5.nam.net|156.154.18.6"

keys [email protected]
Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser4.nam.net|156.154.15.6"

授权文件后:

Keys [email protected]
Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser1.nam.net|156.154.12.1"

Keys [email protected]
Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser2.nam.net|156.154.15.2|ser5.nam.net|156.154.18.6|ser6.nam.net|156.154.18.7|ser7.nam.net|156.154.18.8"

keys [email protected]

Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser3.nam.net|156.154.17.4|ser5.nam.net|156.154.18.6|ser6.nam.net|156.154.18.7|ser7.nam.net|156.154.18.8"

keys [email protected]
Options command="eval $SSH_ORIGINAL_COMMAND",allow-from="ser4.nam.net|156.154.15.6"

答案1

简单地与sed命令:

sed 's/156\.154\.18\.6/&|ser6.nam.net|156.154.18.7|ser7.nam.net|156.154.18.8/' file

要仅在带有 - 的行上执行替换ser2.nam.net,请使用以下命令:

sed '/ser2\.nam\.net/ s/156\.154\.18\.6/&|ser6.nam.net|156.154.18.7|ser7.nam.net|156.154.18.8/' file

相关内容