Passwords 如何在SSH.net中处理密码过期
我使用SSH.net连接到我的Linux。密码每30天过期一次。 要求之一是自动重置密码 但它失败了 在response.error中,它总是 错误“警告:您的密码已过期。\n需要更改密码,但没有可用的TTY。\n” 代码示例如下所示 班级计划 { 字符串host=“host”; int端口=22; 字符串username=“user”; 字符串password=“passwd”; 字符串newpassword=“newpasswd”Passwords 如何在SSH.net中处理密码过期,passwords,ssh.net,Passwords,Ssh.net,我使用SSH.net连接到我的Linux。密码每30天过期一次。 要求之一是自动重置密码 但它失败了 在response.error中,它总是 错误“警告:您的密码已过期。\n需要更改密码,但没有可用的TTY。\n” 代码示例如下所示 班级计划 { 字符串host=“host”; int端口=22; 字符串username=“user”; 字符串password=“passwd”; 字符串newpassword=“newpasswd” PasswordConnectionInfo con
PasswordConnectionInfo connectionInfo;
void HandlePasswordExpired(Object sender, AuthenticationPasswordChangeEventArgs e)
{
e.NewPassword = UTF8Encoding.UTF8.GetBytes(newpassword);
}
void Init()
{
connectionInfo = new PasswordConnectionInfo(host, username, password);
connectionInfo.PasswordExpired += HandlePasswordExpired;
}
void TestConnection()
{
try
{
using (var client = new SshClient(connectionInfo))
{
client.Connect();
var resp = client.RunCommand("ls -l /");
Console.WriteLine("Resp -> {0}", resp.Result);
client.Disconnect();
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
static void Main(string[] args)
{
Program prog = new Program();
prog.Init();
prog.TestConnection();
}
}