Java ʹÓÃSSHÁ¬½ÓLinux ʹÓÃpasswdÃüÁîÐÞ¸ÄÃÜÂë
ʹÓÃInputStreamºÍOutputStreamÀ´»ñµÃÃüÁîÐÐÔËÐнá¹ûºÍÊäÈëÄÚÈÝÊÇÊ×ÏÈÐèÒª¾ß±¸µÄ.
È»ºóÒª½â¾öSSHÁ¬½ÓÎÊÌâ.
ÔÚOpenSourceÏîÄ¿ÀïÕÒµ½ÁËGanymed SSH-2 for Java .ÏÂÔغóÓÐÀý×Ó,µ«ÊÇûÓÐÕÒµ½Óйؽ»»¥ÃüÁîµÄÀý×Ó.ËùÒÔ×Ô¼ºÌ½Ë÷ÁËÒ»ÏÂ
ÔÚÍøÉÏ¿´ÓÐÀÏÍâÌÖÂÛÓÃÕâ¸öÈçºÎ¸ÄÃÜÂë,»ù±¾ÉϵÄÎÊÌⶼÊÇÒòΪÕÒ²»µ½·µ»ØµÄÌáʾ
LinuxÐÞ¸ÄÃÜÂëÊäÈëpasswdºó,Ê×ÏÈÊÇÊäÈ뵱ǰÃÜÂë,È»ºóÊÇÊäÈëÁ½¸öÐÂÃÜÂë
Èç¹ûµ±Ç°ÃÜÂëÊäÈë´íÎó,»òÕßÐÂÃÜÂëÊäÈë²»·ûºÏϵͳÃÜÂë¹æÔòÒªÇó,»áÒªÇóÖØÐÂÊäÈë.Èç¹ûÅöµ½ÕâÖÖÇé¿ö,³ÌÐòºÜÈÝÒ×½øÈëÒ»¸ö²»Ì«ºÃ¿ØÖƵÄÑ»·.
¿ÉÄÜÒ»°ãÈ˶¼ÈÏΪÊäÈëÃüÁîºóËùÓеķµ»Ø¶¼Ó¦¸ÃÊÇÓÃsession.getStdout();¶ø²»ÊÇsession.getStderr();´Ó·½·¨Ãû³ÆÉÏ¿´È·ÊµÈç´Ë,Ò»¸öÊÇÈ¡µÃ±ê×¼Êä³ö,Ò»¸öÊÇÈ¡µÃ´íÎóÐÅÏ¢.
ÆäʵÔÚÊäÈëpasswdºó.
Changing password for user [username].
Changing password for [username]
ÕâÁ½ÐÐÊÇÐèҪͨ¹ýsession.getStdout();À´»ñµÃµÄ.µ«ÊǺóÃæµÄ
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
ÕâÈýÐÐÊÇÐèҪʹÓÃsessssion.getStderr();À´»ñÈ¡µÄ
Èç¹ûÓû§ÊäÈëûÓÐͨ¹ýϵͳ¼ì²â,»á·µ»Ø¾ßÌåÔÒò,µ«ÊǶ¼ÊÇBAD PASSWORD¿ªÊ¼µÄ.
Èç¹û×îºóÐ޸ijɹ¦ÁË.ÄãÒ²»á¿´µ½ÓÐsuccessfullyÀ´±íʾ.ÕâЩÐÅÏ¢ÊÇͨ¹ýsession.getStdout();À´»ñÈ¡µÄ.
ÏÖÔÚÎÊÌâºÜºÃ½â¾öÁË°É.
дÁËÒ»¸öÀàÀ´Íê³ÉÐÞ¸ÄÃÜÂëµÄ²Ù×÷.
ºóÀ´Ê¹ÓÃÕâ¸ö·½·¨,ÏÖÔÚ¹«Ë¾ÄÚ²¿Ð½¨ÕʺÅÒÔ¼°ÕʺÅÉèÖÃ×Ô¶¯Óʼþ»Ø¸´¶¼¿ÉÒÔͨ¹ý×Ô¼ºµÄ¹ÜÀíϵͳÉèÖÃÁË.
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
import com.io.Debug;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
public class ChangeEmailPassword {
private String username = "";
private String oldpassword = "";
private Connection conn = null;
private boolean hasError = false;
private String ErrorMessage = "";
private boolean isSuccessfully = false;
private String SystemMessage = "";
public static final String HOST = "127.0.0.1"; //server ip
public boolean isSuccessfully(){
return isSuccessfully;
}
public boolean isHasError(){
Ïà¹ØÎĵµ£º
ListµÄÓ÷¨
List°üÀ¨List½Ó¿ÚÒÔ¼°List½Ó¿ÚµÄËùÓÐʵÏÖÀà¡£ÒòΪList½Ó¿ÚʵÏÖÁËCollection½Ó¿Ú£¬ËùÒÔList½Ó¿ÚÓµÓÐCollection½Ó¿ÚÌṩµÄËùÓг£Ó÷½·¨£¬ÓÖÒòΪListÊÇÁбíÀàÐÍ£¬ËùÒÔList½Ó¿Ú»¹ÌṩÁËһЩÊʺÏÓÚ×ÔÉíµÄ³£Ó÷½·¨£¬Èç±í1Ëùʾ¡£
±í1 List½Ó¿Ú¶¨ÒåµÄ³£Ó÷½·¨¼°¹¦ÄÜ
´Ó±í1¿ÉÒÔ¿´³ö£¬List½Ó¿ÚÌṩµÄÊʺÏÓÚ×ÔÉíµÄ ......
´«ÖDz¥¿ÍJAVAÅàѵOAÏîÄ¿ ÉóÅúÁ÷תģ¿é(δ)
×ö¹¤×÷£¬×ö¼¼Êõ£¬×îÖ÷ÒªµÄ¾ÍÊÇÓÐÒ»ÖÖרÑеŦÄÜ£¬ÌرðÊÇÔÚѧϰµÄ³õÆڽ׶ÎÒ²ºÜÖØÒª£¬ÒòΪ£¬ÀÏʦÓÀÔ¶²»¿ÉÄÜ°ÑËùÓеÄ֪ʶ½»¸øÄ㣬¾ÍÏñ£¬Äã±»ÄãĸÇ×ÉúÁËÏÂÀ´£¬ËûÊÖ°ÑÊֵĽ̻áÁËÄã×ß·£¬µ«ÊÇÈËÉúµÄ·ȴÊÇÒªÄã×Ô¼ºÈ¥×ßµÄÒ»Ñù¡£ÍùÈÕµÄѧУ£¬Ò²½ö½öÊǽ̻áÁËÄã×öÈ˵ĵÀÀí£¬»òÕßÊÇѧ ......
»úÆ÷¼ÓµçÆô¶¯ºó,BIOS¿ªÊ¼¼ì²â²ÎÊý,ÈçÄÚ´æµÄ´óС,ÈÕÆÚºÍʱ¼ä,´ÅÅÌ
É豸ÒÔ¼°ÕâЩ´ÅÅÌÉ豸ÓÃÀ´Òýµ¼µÄ˳Ðò,ͨ³£Çé¿öÏ£¬BIOS¶¼ÊDZ»ÅäÖóÉÊ×Ïȼì²é
ÈíÇý»òÕß¹âÇý£¨»òÁ½Õ߶¼¼ì²é£©£¬È»ºóÔÙ³¢ÊÔ´ÓÓ²ÅÌÒýµ¼¡£Èç¹ûÔÚÕâЩ¿ÉÒƶ¯µÄÉè
±¸ÖУ¬Ã»ÓÐÕÒµ½¿ÉÒýµ¼µÄ½éÖÊ£¬ÄÇôBIOSͨ³£ÊÇתÏòµÚÒ»¿éÓ²ÅÌ×î³õµÄ¼¸¸öÉÈÇø£¬
Ñ°ÕÒÓÃÓÚ×°ÔزÙ×÷Ï ......
ת×Ô£ºhttp://www.yayu.org/look.php?id=162
µ±´ÅÅÌ´óС³¬¹ý±ê׼ʱ»áÓб¨¾¯Ìáʾ£¬ÕâʱÈç¹ûÕÆÎÕdfºÍduÃüÁîÊǷdz£Ã÷ÖǵÄÑ¡Ôñ¡£
df¿ÉÒԲ鿴һ¼¶Îļþ¼Ð´óС¡¢Ê¹ÓñÈÀý¡¢µµ°¸ÏµÍ³¼°Æä¹ÒÈëµã£¬µ«¶ÔÎļþÈ´ÎÞÄÜΪÁ¦¡£
du¿ÉÒԲ鿴Îļþ¼°Îļþ¼ÐµÄ´óС¡£
Á½ÕßÅäºÏʹÓã ......