linux - Change UNIX password with JAVA -
sorry if english language bad. wanna inquire executing "passwd" command java (i utilize netbeans ide & jsch library)
this code
string username = txtusername.gettext(); string password = txtpassword.gettext(); string ip = txtip.gettext(); int port = 22; session session = null; session session2=null; channelexec channel = null; channel channel2 = null; stringbuffer result = new stringbuffer(); seek { jsch shell = new jsch(); session = shell.getsession(username, ip, port); java.util.properties config = new java.util.properties(); config.put("stricthostkeychecking", "no"); session.setconfig(config); session.setpassword(password); session.connect(3000); channel = (channelexec) session.openchannel("exec"); ((channelexec)channel).setcommand("passwd"); channel.setinputstream(null); channel.setoutputstream(null); ((channelexec)channel).seterrstream(system.err); inputstream in=channel.getinputstream(); outputstream out=channel.getoutputstream(); printstream char_to_send_to_channel = new printstream(out,true); bufferedreader out_from_channel=new bufferedreader(new inputstreamreader(in)); char_to_send_to_channel.println(); string line; channel.connect(); joptionpane.showmessagedialog(null,"channel opened!" +"\n"); // process p = runtime.getruntime().exec("passwd"); byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0) { break; } } } } grab (ioexception ex) { logger.getlogger(connect.class.getname()).log(level.severe, null, ex); } catch(jschexception | headlessexception e){ joptionpane.showmessagedialog(null, e); } }
the problem is, output like
(current) unix password:
and if type / input current unix password,nothing happened. want alter ubuntu server business relationship password, installed on vmware. , run programme on original os. simply, want output interactive (input , output output linux command 'passwd')
whats wrong code? :( need suggestions
passwd
default read straight pty instead of stdin. need pass --stdin
alternative passwd
.
for more information, see answers question: using passwd command within shell script.
java linux command jsch passwd
No comments:
Post a Comment