1
我需要能夠從cron任務或ssh會話中更改用戶的密碼。有一個簡單的方法來做到這一點與bash腳本?如果沒有,可可最簡單的方法是什麼?以編程方式或通過腳本更改Mac OS X用戶密碼
我需要能夠從cron任務或ssh會話中更改用戶的密碼。有一個簡單的方法來做到這一點與bash腳本?如果沒有,可可最簡單的方法是什麼?以編程方式或通過腳本更改Mac OS X用戶密碼
使用passwd
shell命令。
蘋果推出Mac OS中10.5 CSIdentitySetPassword API,允許更改密碼,如下所示:
#import <Collaboration/Collaboration.h>
AuthorizationRef authRef = NULL; // You have to initialize authRef
CBIdentityAuthority *authority = [CBIdentityAuthority defaultIdentityAuthority];
CSIdentityRef identity = [CBIdentity identityWithName:user authority:authority].CSIdentity;
if (CSIdentityGetClass(identity) == kCSIdentityClassUser) {
CSIdentitySetPassword(identity, (__bridge CFStringRef)newPassword);
CSIdentityCommit(identity, authRef, NULL);
}
AuthenticationRef可以如int this響應進行初始化。
不密碼塊重定向輸入?如果沒有,你可以這樣做,但是你必須把所有三行寫到一個文件(原始的,新的,新的),然後重定向它,但我認爲這不應該工作(爲了安全) 。可能是錯的。 – 2008-12-09 18:39:12