The company has some server root password is disabled, some are not disabled, disable the root of the server needs to go through the Tomcat user login system, switch to the root modification port, no disabled directly modify the root password;
#-*-coding:utf-8-*-ImportParamikoImport Time" "Remote Login Modify Port" "defSsh_connect (_host, _username, _password):Try: _SSH_FD=Paramiko. Sshclient () _ssh_fd.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) _ssh_fd.connect (_host, username= _username, Password =_password)exceptException as E:return('ssh%[email protected]%s:%s'%(_username, _host, e))return_SSH_FDdefssh_exec_cmd (_SSH_FD, _cmd):return_ssh_fd.exec_command (_cmd)defremote_ssh (_ssh_fd,cmd,root_pwd): SSH=_ssh_fd.invoke_shell () time.sleep (0.1) Ssh.send ('Su-\ n') Buff="' while notBuff.endswith ('Password:'): Resp= SSH.RECV (9999) Buff+=resp ssh.send (root_pwd) ssh.send ('\ n') Buff="' while notBuff.endswith ('# '): Resp= SSH.RECV (9999) Buff+=resp ssh.send (cmd) ssh.send ('\ n') Buff="' while notBuff.endswith ('# '): Resp= SSH.RECV (9999) Buff+=resp _ssh_fd.close () result=BuffreturnresultdefSsh_close (_SSH_FD): _ssh_fd.close ()defMain (): hostname= ['xxx.xx.xx.xx'] Username= ['Root','Tomcat'] Password= ['********','*********'] cmd='echo "Port 61822" >>/etc/ssh/sshd_config && service sshd Restart' forIinchRange (LEN (hostname)): sshd=Ssh_connect (Hostname[i], username[0], password[0])if "Authentication failed" inchStr (sshd):Print 'Permitrootlogin No'sshd= Ssh_connect (Hostname[i], username[1], password[1]) Printremote_ssh (sshd,cmd,password[0])Else: Print 'Permitrootlogin Yes'stdin, stdout, stderr=ssh_exec_cmd (sshd, cmd) stdout_list=Stdout.readlines ()Printstdout_listif __name__=="__main__": #PassMain ()
Telnet to the Linux server to modify the SSH port