Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:33:14+00:00 2026-06-08T18:33:14+00:00

Given a configuration file, such as sshd_config: […] IgnoreRhosts yes RhostsRSAAuthentication no HostbasedAuthentication no

  • 0

Given a configuration file, such as sshd_config:

[...]
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
PasswordAuthentication yes
X11Forwarding yes
X11DisplayOffset 10
[...]

I would like to write a command that lets me set a configuration setting. For example, I want to set PasswordAuthentication to no. If the entry already exists, I want to replace it, if it doesn’t, I want to add it at the end of the file.

How can I do that from the shell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:33:16+00:00Added an answer on June 8, 2026 at 6:33 pm

    You can use awk to do this. Here is a script I wrote:

    $ cat setProp.sh
    #!/bin/sh
    
    propFile=$1
    key=$2
    value=$3
    
    awk -v "key=$key" -v "value=$value" '{
        if($1==key) {
            found=1
            print $1" "value
        } else {
            print
        }
    }
    END {
        if(!found) print key" "value
    }' $propFile
    

    Usage:

    $ setProp.sh myfile RhostsRSAAuthentication no
    IgnoreRhosts yes
    RhostsRSAAuthentication no
    HostbasedAuthentication no
    PermitEmptyPasswords no
    ChallengeResponseAuthentication no
    PasswordAuthentication yes
    X11Forwarding yes
    X11DisplayOffset 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Ruby I frequently use File.dirname(__FILE__) to open configuration files and such. For those
Problem Given the following XML configuration file: <main> <name>JET</name> <maxInstances>5</maxInstances> <parameters> <a>1</a> <b> <b1>test1</b1>
I have the following requirement: In C#2.0, Given a device configuration in xml format
I have modified my MOSS 2007 configuration to query a given target AD successfully.
How to streamline/automate the configuration of Eclipse? Given N developers running a mixture of
My application have a configuration xml-file. That file contains more than 50 program settings.
Once upon a time, I had a 'DEV' configuration and a 'Web.DEV.config' transformation file
I was trying to add some configuration in web.config file after the web page
Please help me parse a configuration file of the below prototype using lxml etree.
I have to extract a parameter from a configuration file, and replace its values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.