顯示具有 Windows 相關 標籤的文章。 顯示所有文章
顯示具有 Windows 相關 標籤的文章。 顯示所有文章

2026年2月4日 星期三

Debian 13 安裝 Samba 升級 DC 建立網域

安裝軟體
apt install -y sudo
apt install -y samba-ad-dc winbind libpam-winbind libnss-winbind
apt install -y acl attr samba samba-dsdb-modules samba-vfs-modules winbind libpam-winbind libnss-winbind libpam-krb5 krb5-config krb5-user dnsutils net-tools

apt install samba krb5-config winbind smbclient -y
apt install ldb-tools  -y

systemctl stop smbd nmbd winbind
systemctl disable smbd nmbd winbind
systemctl mask smbd nmbd winbind

升級 Domain Controller
mv /etc/samba/smb.conf /etc/samba/smb.conf.ori
samba-tool domain provision --use-rfc2307 --interactive

mv /etc/krb5.conf /etc/krb5.conf.ori
ln -s /var/lib/samba/private/krb5.conf /etc/krb5.conf   

systemctl start samba-ad-dc

測試
smbclient -L localhost -U%
samba-tool domain level show

2025年12月8日 星期一

Proxmox VE 9.x 建立 Windows 2K VM

VM 相關設定
BIOS:    Default(SeaBIOS)
Display: Standard VGA
Machine: Default(i440fx)
SCSI Controller: Default(LSI 只C895A)
Hard Disk(ide0)
Network Devivce: Realtek RTL8139

安裝 Windows 2000 後安裝 Universal VBE Video Display Driverhttps://bearwindows.zcm.com.au/vbemp.htm

2025年9月9日 星期二

Debian 13 使用 sssd 加入 domain

apt install -y adcli realmd krb5-user samba-common-bin samba-libs samba-dsdb-modules sssd sssd-tools libnss-sss libpam-sss packagekit polkitd  pkexec

/etc/sssd/sssd.conf  設定檔
[sssd]
domains = ad.example
config_file_version = 2
services = nss, pam

[domain/tw.example]
ad_domain = ad.example
krb5_realm = AD.EXAMPLE
realmd_tags = manages-system joined-with-samba
cache_credentials = True
id_provider = ad
krb5_store_password_if_offline = True
default_shell = /bin/bash
ldap_id_mapping = True
use_fully_qualified_names = False    #登入時,不需輸入網域
fallback_homedir = /home/%d/%u       #自動建立的 home 目錄不會加上 @DomainName
access_provider = ad
enumerate = true       #可 使用 getent 查詢帳號資訊
ad_gpo_map_interactive = +xrdp-sesman

編輯 /etc/pam.d/common-session
# add to the end if need (create home directory automatically at initial login)
session optional        pam_mkhomedir.so skel=/etc/skel umask=077

修正服務
systemctl disable sssd-pac.socket
systemctl disable sssd-pam.socket
systemctl disable sssd-nss.socket

2025年9月1日 星期一

Windows AD accountExpires屬性

建立帳戶時,帳戶一開始會設定為 永不過期。
accountExpires 屬性預設值 9223372036854775807 ,對應 64 位帶正負號整數的最大值
帳戶設定到期日, accountExpires 設定為到期日的 FILETIME 值
帳戶設定到期時間為永不過期, accountExpires 設定為 0 

PHP 查詢 Windows AD objectGUID objectSid (string fromat)

 <?php
function objectSid($binary_sid) {
    if(strlen(decbin(~0)) == 64)  //64bit PHP
    {
        // Get revision, indentifier, authority
        $parts = unpack('Crev/x/nidhigh/Nidlow', $binary_sid);
        // Set revision, indentifier, authority
        $sid = sprintf('S-%u-%d',  $parts['rev'], ($parts['idhigh']<<32) + $parts['idlow']);
        // Translate domain
        $parts = unpack('x8/V*', $binary_sid);
        // Append if parts exists
        if ($parts) $sid .= '-';
        // Join all
        return $sid.= join('-', $parts);
    }
     //32bit PHP
    $sid = 'S-';
    $sidinhex = str_split(bin2hex($binary_sid), 2);
    // Byte 0 = Revision Level
    $sid = $sid.hexdec($sidinhex[0]).'-';
    // Byte 1-7 = 48 Bit Authority
    $sid = $sid.hexdec($sidinhex[6].$sidinhex[5].$sidinhex[4].$sidinhex[3].$sidinhex[2].$sidinhex[1]);
    // Byte 8 count of sub authorities - Get number of sub-authorities
    $subauths = hexdec($sidinhex[7]);
    //Loop through Sub Authorities
    for($i = 0; $i < $subauths; $i++) {
        $start = 8 + (4 * $i);
        // X amount of 32Bit (4 Byte) Sub Authorities
        $sid = $sid.'-'.hexdec($sidinhex[$start+3].$sidinhex[$start+2].$sidinhex[$start+1].$sidinhex[$start]);
    }
    return $sid;
}

function objectGUID($binaryGuid) {
    $hexGuid = bin2hex($binaryGuid);
    // Reorder and format according to standard GUID representation
    $hex1 = substr($hexGuid, 6, 2) . substr($hexGuid, 4, 2) . substr($hexGuid, 2, 2) . substr($hexGuid, 0, 2);
    $hex2 = substr($hexGuid, 10, 2) . substr($hexGuid, 8, 2);
    $hex3 = substr($hexGuid, 14, 2) . substr($hexGuid, 12, 2);
    $hex4 = substr($hexGuid, 16, 4);
    $hex5 = substr($hexGuid, 20, 12);
    return sprintf('%s-%s-%s-%s-%s', $hex1, $hex2, $hex3, $hex4, $hex5);
}

$user = 'user1';         //設定欲認證的帳號名稱
$ldappass = 'p@ssw0rd';  //設定欲認證的帳號密碼
$domain = 'test.loc';   //設定網域名稱

putenv('LDAPTLS_REQCERT=allow');
$ldapconn = @ldap_connect("ldaps://" . $domain) or die("無法連接至 $domain");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) { // binding to ldap server
    $ldapbind = @ldap_bind($ldapconn, $user . '@' . $domain, $ldappass);
    if ($ldapbind) {  // verify binding
        $result = @ldap_search($ldapconn, sprintf("dc=%s", (str_replace(".", ",dc=", $domain))), "(sAMAccountName=$user)");

        if($result==false) echo "認證失敗";
        else {
          $entries = ldap_get_entries($ldapconn, $result);
          $results2 = ldap_search($ldapconn, sprintf("dc=%s", (str_replace(".", ",dc=", $domain))),"(&(objectclass=group)(objectsid=*))", array("cn", "objectguid"));
          $entries2 = ldap_get_entries($ldapconn, $results2);

          for ($i=1; $i<$entries2['count']; $i++)
            echo $entries2[$i]['cn'][0] . "\n" . objectGUID($entries2[$i]['objectguid'][0]) . "\n" . objectSid($entries2[$i]['objectsid'][0]) . "\n\n";
        }
    } else echo "認證失敗...";
}
?>

2025年7月23日 星期三

X2GO Windows 版本清除設定異常

移除 X2GO

執行 regedit 
刪除 HKEY_CURRENT_USER\Software\Obviously Nice\x2goclient  資料夾

重新安裝 X2GO

2025年6月23日 星期一

Windows 10/11 powershell 下新增VPN

 Add-VpnConnection -Name "VPN-NAME" -ServerAddress "vpn-server" -PassThru -TunnelType "Automatic" 

-TunnelType
指定用於VPN連接的 Tunnel類型。此參數的可接受值為:
PPTP  L2TP  SSTP  IKEv2  Automatic

2025年6月5日 星期四

Debian 12 sssd realm 無法加入網域

錯誤訊息
Wrote out krb5.conf snippet to /var/cache/realmd/adcli-krb5-090dt5/krb5.d/adcli-krb5-conf-uzvObj
 * Authenticated as user: Administrator@test.loc
 * Using GSS-SPNEGO for SASL bind
 ! Couldn't authenticate to active directory: SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure.  Minor code may provide more information (Server not found in Kerberos database)
adcli: couldn't connect to ssde.sinica domain: Couldn't authenticate to active directory: SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure.  Minor code may provide more information (Server not found in Kerberos database)
Insufficient permissions to join the domain

安裝 krb5相關軟體
apt install krb5-user

2025年5月27日 星期二

Windows 連線 VPN 指令

rasdial.exe "VPNName" "Username" "Password"

rasdial.exe "VPNName" /DISCONNECT

2025年1月10日 星期五

Windows 11 WSL 中文輸入 fcitx5

安裝
sudo apt install fcitx5 fcitx5-* # 全部Fcitx5支援的輸入法
sudo apt install fcitx5-chinese-addons fcitx5-chewing  # 只安裝新酷音注音
sudo apt install fcitx5-table-easy-large fcitx5-chinese-addons #只安裝輕鬆
sudo apt install fcitx5-frontend-gtk2 fcitx5-frontend-gtk3 fcitx5-frontend-gtk4 fcitx5-frontend-qt5 fcitx5-frontend-qt6

執行 
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &>/dev/null

相關設定
im-config
fcitx5-configtool

export WAYLAND_DISPLAY='wayland-0' DISPLAY=':0'

2024年12月10日 星期二

Windows 10 的遠端伺服器管理工具(RSAT)

下載
https://www.microsoft.com/zh-tw/download/details.aspx?id=45520&msockid=1cc89087a3bc684704e9853ea2f06919

安裝
應用程式->選用功能->檢視功能

Powershell 相關指令
Get-WindowsCapability -Online -Name RSAT*
Add-WindowsCapability –Online –Name "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0"
Remove-WindowsCapability -Online -Name "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0"

執行
以管理者身分執行終端機

runas /netonly /user:tpha\administrator "mmc /server=dc-ip"

額外說明
不用加入網域

Debian12 Samba-Tool 移除 domain controller

登入移除要移除的 samba dc
samba-tool domain demote -Uadministrator

登入主要 samba dc
samba-tool domain demote --remove-other-dead-server=<上述移除 dc 主機名 windows-ad>

2024年10月30日 星期三

WSL 無法執行 Systemd

錯誤訊息
System has not been booted with systemd as init system (PID 1). Can't operate.

編輯 /etc/wsl.conf 添加以下內容:
[boot]
systemd=true

2024年10月23日 星期三

Windows 11 安裝略過網路設定、使用本機帳號

 Shift + F10 命令提示字元的視窗 

輸入 oobe\bypassnro

2024年7月16日 星期二

列出 sss 所有帳號

編輯 /etc/sssd/sssd.conf 加入
enumerate = true

指令
getent -s files passwd
getent -s sss   passwd
getent          passwd

2024年5月7日 星期二

Debian 12 join Windows AD

apt -y install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit  krb5-user

錯誤訊息 Couldn't get kerberos ticket for: Administrator Cannot contact any KDC for realm
檢查網路及主機名稱

2022年3月22日 星期二

Debian 11 Samba 使用 Winbind 認證

安裝軟體
apt -y install winbind libpam-winbind libnss-winbind krb5-config samba-dsdb-modules samba-vfs-modules
 
編輯 /etc/krb5.conf  
[libdefaults]
        default_realm = TEST.COM
 
# The following krb5.conf variables are only for MIT Kerberos.
       kdc_timesync = 1
        ccache_type = 4
        forwardable = true
        proxiable = true
 
編輯 /etc/samba/smb.conf
[global]   
   workgroup = TEST
   realm = TEST.DOM
   security = ads
   idmap config * : backend = tdb
   idmap config * : range = 3000-7999
   idmap config FD3S01 : backend = rid
   idmap config FD3S01 : range = 10000-999999
   template homedir = /home/%U
   template shell = /bin/bash
   winbind use default domain = true
   winbind offline logon = false
 
[homes]
   comment = Home Directories
   browseable = no
   read only = no
   create mask = 0755
   directory mask = 0755
   valid users = %S
   root preexec = /opt/mkmyhome.sh %S %H
#   hide files = /abc/ /a/ /.*/
 
編輯 /etc/nsswitch.conf 修改
passwd:         files systemd winbind
group:          files systemd winbind
 
編輯 /etc/pam.d/common-session  加入
# add to the end if you need (auto create a home directory at initial login)
session optional        pam_mkhomedir.so skel=/etc/skel umask=077

編輯 /opt/mkmyhome.sh
#!/bin/bash
user=$1
home=$2
group="domain users"

[ -z "$user" ]&&exit 9;
[ -z "$home" ]&&exit 9;
[ -d "$home" ]&&exit 9;

mkdir -p $home -m 700  && chown "${user}:${group}" $home;
exit $?;

chmod a+x /opt/mkmyhome.sh

加入網域

net ads join -U Administrator
 
重啟服務
 systemctl restart winbind

其他相關指令
net ads leave -U Administrator

2022年2月14日 星期一

Windows 10 限制 RDP 資源

執行 gpedit

電腦設定\原則\系統管理範本\Windows元件\遠端桌面服務\遠端桌面工作階段主機\裝置及資源重新導向\

2021年1月18日 星期一

windows 10 使用 sshfs

安裝軟體
https://github.com/billziss-gh/sshfs-win/releases
https://github.com/billziss-gh/winfsp/releases/tag/v1.8

指令
net use z: \\sshfs\root@192.168.1.1\..     (/)
net use z: \\sshfs\root@192.168.1.1\zz    (/root/zz)