Script to check and modify /etc/ssh/sshd_config


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check and modify /etc/ssh/sshd_config
# 1  
Old 06-02-2013
Script to check and modify /etc/ssh/sshd_config

Hi,

How can I check and modify /etc/ssh/sshd_config parameters in a script? I'll particular to check and enable / disable PasswordAuthentication and PubkeyAuthentication. I know I can edit sshd_config by vi, but for some reason we need change it in a script.

Thank you.

hce
# 2  
Old 06-02-2013
In case you aren't aware, you can override sshd_config settings with command options.

Regards,
Alister
# 3  
Old 06-02-2013
Quote:
Originally Posted by alister
In case you aren't aware, you can override sshd_config settings with command options.
Thanks Alister, could you please give an example of how to change "PasswordAuthentication = yes" in the command options?

Thank you.

Kind regards.
# 4  
Old 06-02-2013
From man ssh :

Quote:
-o option
Can be used to give options in the format used in the configuration file. This is useful for specifying
options for which there is no separate command-line flag. For full details of the options listed below,
and their possible values, see ssh_config(5).
# 5  
Old 06-02-2013
Quote:
Originally Posted by mirni
From man ssh :
Thanks mirni, but I tried:


ssh -o PasswordAuthentication=yes root@remote_vm

It did not work. Not clear if we are in the same page. I actually asked how to change the /etc/ssh/sshd_config which defines "PasswordAuthentication no" by command line in script in the remote_vm machine. I guess the ssh -o option is only to change /etc/ssh/ssh_config setting, is it correct?

Thank you.

Kind regards.
# 6  
Old 06-02-2013
Quote:
Originally Posted by hce
Thanks Alister, could you please give an example of how to change "PasswordAuthentication = yes" in the command options?
Have a look at your sshd man page. The answer is there.

And, in case it isn't obvious, an ssh client can't override a server's settings. That would be very insecure.

Regards,
Alister
# 7  
Old 06-02-2013
Yes, command line options are for ssh, and they override ssh_config.
For changing existing options in sshd_config you can use awk
Code:
file=/etc/ssh/sshd_config
cp -p $file $file.old &&
awk '
$1=="PasswordAuthentication" {$2="yes"}
$1=="PubkeyAuthentication" {$2="yes"}
{print}
' $file.old > $file

or do it in a shell loop
Code:
file=/etc/ssh/sshd_config
cp -p $file $file.old &&
while read key other
do
 case $key in
 PasswordAuthentication) other=yes;;
 PubkeyAuthentication) other=yes;;
 esac
 echo "$key $other"
done < $file.old > $file


Last edited by MadeInGermany; 06-02-2013 at 10:50 AM.. Reason: read line/set replaced by read key other
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris local access restriction other than sshd_config?

Hi All, As part of LDAP implementation we need to restrict users/groups locally on solaris machine: Options tried: sshd_config: as far as my testing it is restricting either user or group, as per the first preference. pam_access.so by default I am unable to find(need some help if this is... (0 Replies)
Discussion started by: Sridaran
0 Replies

2. Red Hat

Sshd_config file issue, not able to login, need urgent help.

Hello all, By mistake i edited sshd_config file and made passwordauthentication no , Now i don't have key to login. Is there any way, i can revert the changes, I am not able to login to the box at well. Need help. Thanks, saurau (3 Replies)
Discussion started by: saurau
3 Replies

3. Shell Programming and Scripting

Check if file exists via ssh in ssh (nested)

I'm using redhat and have an odd issue with a nested ssh call. ssh -i ~/.ssh/transfer-key -q transfer@fserver1 ] && ssh -i ~/.ssh/transfer-key transfer@fserver1 "ssh -i ~/.ssh/sftp-key sftpin@10.0.0.1 ]" && ssh -i ~/.ssh/transfer-key transfer@fserver1 "scp -i ~/.ssh/sftp-key /home/S/outbox/*... (2 Replies)
Discussion started by: say170
2 Replies

4. UNIX for Advanced & Expert Users

OEL 6.3 :Slow login due to /etc/ssh/sshd_config configuration

Version: Oracle Enterprise Linux 6.3 Running on VMWare Workstation When I login to my Linux VM from putty, the third line prompting for password comes only after few seconds. login as: root Access denied root@192.168.0.235's password: ---> It takes around 5 seconds to get this prompt I... (1 Reply)
Discussion started by: John K
1 Replies

5. Shell Programming and Scripting

MaxAuthTries in sshd_config

I am not able to determine if the above setting is for outgoing or incoming connections. I do not have the rights to change it on my system to try this out. Anyone can help shed some light on this? Thank you. (2 Replies)
Discussion started by: Leion
2 Replies

6. Solaris

default Sun_SSH_1.1.1 sshd_config

I have what should be a simple request, (I hope so anyways), I need the default sshd_config for Sun SSH 1.1.1. A series of scripts modify our systems to work with the rest of our system. They are supposed to create backups along the way, but alas, it seems a few too many people like the filename... (1 Reply)
Discussion started by: Corry
1 Replies

7. AIX

sshd_config default

Hi All, On sshd_config remark, many of the lines are commented out, like below #PubkeyAuthentication yes Does that mean the default of PubkeyAuthentication is no (or yes)? Thanks for any comment you may add. edit by bakunin: corrected a typo in the title to preserve searchability... (2 Replies)
Discussion started by: itik
2 Replies

8. Red Hat

sshd_config default configuration

Hi All, On /etc/ssh/sshd_config remark, many of the lines are commented out, like below #PubkeyAuthentication yes Does that mean the default of PubkeyAuthentication is no (or yes)? Thanks for any comment you may add. (1 Reply)
Discussion started by: itik
1 Replies

9. Shell Programming and Scripting

Script check if ssh requires a password???

Thanks to the help from this forum i've learned a lot of good stuff but I still have questions :). I need to write a script that checks if ssh to a box requires a password. I need it will be an "if" statement, if ssh requires password, then do a key exchange(with i already have). Just need to... (5 Replies)
Discussion started by: elbombillo
5 Replies

10. Shell Programming and Scripting

diff between ssh_config & sshd_config

Hi, Can anybody brief me the difference between ssh_config & sshd_config. I am looking for the functionality difference. any help appreciated Shihab (4 Replies)
Discussion started by: shihabvk
4 Replies
Login or Register to Ask a Question