重点注意的是:
1.分区文件 cat /etc/fstab
sr658@sr658:/home$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/ubuntu-vg/lv-0 during curtin installation
/dev/disk/by-id/dm-uuid-LVM-LURBGaZZop2eWLXH8f5EF0LuF5Brq3mxcFfxNNTew7ZT2ptlkpSh2Kt1aEUm8F9T / ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/a7c8d69c-38e0-4689-95dc-5fdb68bf8c7f /boot ext4 defaults 0 1
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/F969-1D50 /boot/efi vfat defaults 0 1
/swap.img none swap sw 0 0
#old fj
#/dev/sdb1 /home/fj/space_3T ext4 defaults 0 2
#/dev/mapper/ubuntu--vg-lvm3--lv /home/hzs ext4 defaults 0 2 //old server: 172.17.9.235
#/dev/mapper/ubuntu--vg-hzs--lv /home/hzs ext4 defaults 0 2 //old hzs user and replace by optmv_sci2_user01 2026-06-22
/dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01 ext4 defaults 0 2
/dev/mapper/ubuntu--vg-fj--lv /home/fj ext4 defaults 0 2
/dev/mapper/ubuntu--vg-optmv--lv /home/optmv ext4 defaults 0 2
#/dev/mapper/ubuntu--vg-dev1--lv /home/dev1 ext4 defaults 0 2 //old dev1 user and replace by optmv_sci2_user01 2026-06-22
/dev/mapper/ubuntu--vg-dev1--lv /home/optmv_sci2_user03 ext4 defaults 0 2
#/dev/mapper/ubuntu--vg-lqs--lv /home/lqs ext4 defaults 0 2 //old lqs user and replace by optmv_sci2_user01 2026-06-22
/dev/mapper/ubuntu--vg-lqs--lv /home/optmv_sci2_user02 ext4 defaults 0 2
sr658@sr658:/home$
-
samba的配置文件
sr658@sr658:/home$ cat /etc/samba/smb.conf
Sample configuration file for the Samba suite for Debian GNU/Linux.
This is the main Samba configuration file. You should read the
smb.conf(5) manual page in order to understand the options listed
here. Samba has a huge number of configurable options most of which
are not shown in this example
Some options that are often worth tuning have been included as
commented-out examples in this file.
- When such options are commented with ";", the proposed setting
differs from the default Samba behaviour
- When commented with "#", the proposed setting is the default
behaviour of Samba but the option is considered important
enough to be mentioned here
NOTE: Whenever you modify this file you should run the command
"testparm" to check that you have not made any basic syntactic
errors.
#======================= Global Settings =======================
[global]
Browsing/Identification
Change this to the workgroup/NT-domain name your Samba server will part of
workgroup = WORKGROUPserver string is the equivalent of the NT Description field
server string = %h server (Samba, Ubuntu)Networking
The specific set of interfaces / networks to bind to
This can be either the interface name or an IP address/netmask;
interface names are normally preferred
; interfaces = 127.0.0.0/8 eth0
Only bind to the named interfaces and/or networks; you must use the
'interfaces' option above to use this.
It is recommended that you enable this feature if your Samba machine is
not protected by a firewall or is a firewall itself. However, this
option cannot handle dynamic or non-broadcast interfaces correctly.
; bind interfaces only = yes
Debugging/Accounting
This tells Samba to use a separate log file for each machine
that connects
log file = /var/log/samba/log.%mCap the size of the individual log files (in KiB).
max log size = 1000We want Samba to only log to /var/log/samba/log.{smbd,nmbd}.
Append syslog@1 if you want important messages to be sent to syslog too.
logging = fileDo something sensible when Samba crashes: mail the admin a backtrace
panic action = /usr/share/samba/panic-action %d####### Authentication #######
Server role. Defines in which mode Samba will operate. Possible
values are "standalone server", "member server", "classic primary
domain controller", "classic backup domain controller", "active
directory domain controller".
Most people will want "standalone server" or "member server".
Running as "active directory domain controller" will require first
running "samba-tool domain provision" to wipe databases and create a
new domain.
server role = standalone server obey pam restrictions = yesThis boolean parameter controls whether Samba attempts to sync the Unix
password with the SMB password when the encrypted SMB password in the
passdb is changed.
unix password sync = yesFor Unix password sync to work on a Debian GNU/Linux system, the following
parameters must be set (thanks to Ian Kahan <kahan@informatik.tu-muenchen.de for
sending the correct chat script for the passwd program in Debian Sarge).
passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .This boolean controls whether PAM will be used for password changes
when requested by an SMB client instead of the program listed in
'passwd program'. The default is 'no'.
pam password change = yesThis option controls how unsuccessful authentication attempts are mapped
to anonymous connections
map to guest = bad user########## Domains ###########
The following settings only takes effect if 'server role = classic
primary domain controller', 'server role = classic backup domain controller'
or 'domain logons' is set
It specifies the location of the user's
profile directory from the client point of view) The following
required a [profiles] share to be setup on the samba server (see
below)
; logon path = \%N\profiles%U
Another common choice is storing the profile in the user's home directory
(this is Samba's default)
logon path = \%N%U\profile
The following setting only takes effect if 'domain logons' is set
It specifies the location of a user's home directory (from the client
point of view)
; logon drive = H:
logon home = \%N%U
The following setting only takes effect if 'domain logons' is set
It specifies the script to run during logon. The script must be stored
in the [netlogon] share
NOTE: Must be store in 'DOS' file format convention
; logon script = logon.cmd
This allows Unix users to be created on the domain controller via the SAMR
RPC pipe. The example command creates a user account with a disabled Unix
password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u
This allows machine accounts to be created on the domain controller via the
SAMR RPC pipe.
The following assumes a "machines" group exists on the system
; add machine script = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u
This allows Unix groups to be created on the domain controller via the SAMR
RPC pipe.
; add group script = /usr/sbin/addgroup --force-badname %g
############ Misc ############
Using the following line enables you to customise your configuration
on a per machine basis. The %m gets replaced with the netbios name
of the machine that is connecting
; include = /home/samba/etc/smb.conf.%m
Some defaults for winbind (make sure you're not using the ranges
for something else.)
; idmap config * : backend = tdb
; idmap config * : range = 3000-7999
; idmap config YOURDOMAINHERE : backend = tdb
; idmap config YOURDOMAINHERE : range = 100000-999999
; template shell = /bin/bashSetup usershare options to enable non-root users to share folders
with the net usershare command.
Maximum number of usershare. 0 means that usershare is disabled.
usershare max shares = 100
Allow users who've been granted usershare privileges to create
public shares, not just authenticated ones
usershare allow guests = yes#======================= Share Definitions =======================
Un-comment the following (and tweak the other settings below to suit)
to enable the default home directory shares. This will share each
user's home directory as \server\username
;[homes]
; comment = Home Directories
; browseable = noBy default, the home directories are exported read-only. Change the
next parameter to 'no' if you want to be able to write to them.
; read only = yes
File creation mask is set to 0700 for security reasons. If you want to
create files with group=rw permissions, set next parameter to 0775.
; create mask = 0700
Directory creation mask is set to 0700 for security reasons. If you want to
create dirs. with group=rw permissions, set next parameter to 0775.
; directory mask = 0700
By default, \server\username shares can be connected to by anyone
with access to the samba server.
Un-comment the following parameter to make sure that only "username"
can connect to \server\username
This might need tweaking when using external authentication schemes
; valid users = %S
Un-comment the following and create the netlogon directory for Domain Logons
(you need to configure Samba to act as a domain controller too.)
;[netlogon]
; comment = Network Logon Service
; path = /home/samba/netlogon
; guest ok = yes
; read only = yesUn-comment the following and create the profiles directory to store
users profiles (see the "logon path" option above)
(you need to configure Samba to act as a domain controller too.)
The path below should be writable by all users so that their
profile directory may be created the first time they log on
;[profiles]
; comment = Users profiles
; path = /home/samba/profiles
; guest ok = no
; browseable = no
; create mask = 0600
; directory mask = 0700[printers]
comment = All Printers
browseable = no
path = /var/tmp
printable = yes
guest ok = no
read only = yes
create mask = 0700Windows clients look for this share name as a source of downloadable
printer drivers
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = noUncomment to allow remote administration of Windows print drivers.
You may need to replace 'lpadmin' with the name of the group your
admin users are members of.
Please note that you also need to set appropriate Unix permissions
to the drivers directory for these users to have write rights in it
; write list = root, @lpadmin
These folders are only for linux personal users.
#[hzs]
path = /home/hzs
writeable = yes
public=yes
#; browseable = yes
valid users = hzs
[optmv_sci2_user01]
path = /home/optmv_sci2_user01
writeable = yes
public=yes
; browseable = yes
valid users = optmv_sci2_user01[fj]
path = /home/fj
writeable = yes
public=yes
; browseable = yes
valid users = fj[optmv]
path = /home/optmv
writeable = yes
public=yes
; browseable = yes
valid users = optmv#[dev1]
path = /home/dev1
writeable = yes
public=yes
#; browseable = yes
valid users = dev1
[optmv_sci2_user03]
path = /home/optmv_sci2_user03
writeable = yes
public=yes
; browseable = yes
valid users = optmv_sci2_user03#[lqs]
path = /home/lqs
writeable = yes
public=yes
#; browseable = yes
valid users = lqs
[optmv_sci2_user02]
path = /home/optmv_sci2_user02
writeable = yes
public=yes
; browseable = yes
valid users = optmv_sci2_user02
sr658@sr658:/home$
将dev1更新为optmv_sci2_user02
1512 cd ../
1513 ls -lh
1514 cd /home/
1515 ls -lh
1516 ls -l dev1/
1517 echo "start rename dev1 to optmv_sci2_user03"
1518 sudo rm -rf dev1/
1519 sudo umount -f /home/dev1
1520 sudo vim /etc/fstab
1521 ls
1522 sudo adduser optmv_sci2_user03
1523 who
1524 ls -l /home/
1525 cat /etc/fstab
1526 ls -l /dev/
1527 cd dev1/
1528 ls
1529 sudo dev1/
1530 sudo cd dev1/
1531 ls -lh
1532 cd dev1/
1533 cat /etc/fstab
1534 ls -lh
1535 cd lqs/
1536 ls -l lqs/
1537 sudo ls -l lqs/
1538 rm -rf lqs/
1539 sudo rm -rf lqs/
1540 ls -lh
1541 ls -l dev1/
1542 sudo ls -l dev1/
1543 rm -rf dev1/
1544 sudo rm -rf dev1/
1545 ls -lh
1546 cat /etc/fstab
1547 sudo mount -f /dev/mapper/ubuntu--vg-dev1--lv /home/optmv_sci2_user03/
1548 systemctl daemon-reload
1549 sudo systemctl daemon-reload
1550 sudo mount -f /dev/mapper/ubuntu--vg-dev1--lv /home/optmv_sci2_user03/
1551 cat /etc/samba/smb.conf
1552 sudo vim /etc/samba/smb.conf
1553 sync
1554 sudo systemctl restart smbd.service
1555 sudo systemctl restart nmbd.service
1556 sudo usermod -g optmv_sci2_user03 optmv_sci2_user03
1557 sudo passwd optmv_sci2_user02
1558 sudo passwd optmv_sci2_user03
1559 sudo smbpasswd optmv_sci2_user03
1560 ls -l /home/optmv_sci2_user03/
1561 sudo ls -l /home/optmv_sci2_user03/
1562 sudo useradd -m -d /home/optmv_sci2_user03 -s /bin/bash -g optmv_sci2_user03 optmv_sci2_user03
1563 ls -l /home/
1564 sudo chmod 755 /home/optmv_sci2_user03
1565 ls -l /home/
1566 sudo smbpasswd optmv_sci2_user03
1567 cd ~
1568 sudo smbpasswd optmv_sci2_user03
1569 sudo useradd -m -d /home/optmv_sci2_user03 -s /bin/bash -g optmv_sci2_user03 optmv_sci2_user03
1570 sudo passwd optmv_sci2_user03
1571 sudo smbpasswd -a optmv_sci2_user03
1572 top
1573 clear
1574 ls -lh
1575 cd /home/
1576 ls -lh
1577 ip addr
1578 clear
1579 ls -lh
1580 history |grep optmv_sci2_user03
1581 history 70 > ~/Bakup/add_optmv_sci2_user03.txt
将lqs更新为optmv_sci2_user02
1298 ls -l /home/
1299 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01
1300 cat /etc/fstab
1301 sudo pvs
1302 fdisk
1303 fdisk -lh
1304 fdisk -L
1305 lsblk
1306 sudo fdisk -l /dev/sdb
1307 sudo umount -f /home/hzs
1308 sudo pkill -9 -u hzs
1309 sudo fuser -km /home/hzs/
1310 sudo umount -f /home/hzs
1311 sudo lsof /home/hzs/
1312 sudo mount -f /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1313 df -h |grep optmv_sci
1314 mount |grep opt_sci
1315 ls -ls /home/optmv_sci2_user01/
1316 grep optmv_sci2_user01 /etc/passwd
1317 ls -lh
1318 ls -lh /home/
1319 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1320 sudo chmod 755 /home/optmv_sci2_user01/
1321 ls -lh
1322 ls -lh /home/
1323 rm -rf /home/hzs/
1324 sudo rm -rf /home/hzs/
1325 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1326 ls -lh
1327 ls -lh /home/
1328 sudo umount -l /home/hz
1329 ls -lh
1330 ls -lh /home/
1331 df -h /home/optmv_sci2_user01/
1332 sudo adduser optmv_sci2_user01
1333 sudo smbpasswd -a optmv_sci2_user01
1334 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1335 ls -l /home/
1336 id optmv_sci2_user01
1337 sudo groupadd optmv_sci2_user01
1338 sudo usermod -g optmv_sci2_user01 optmv_sci2_user01
1339 id optmv_sci2_user01
1340 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1341 how
1342 who
1343 ls -lh
1344 ls -lh /home/
1345 ls -l /home/optmv
1346 ls -l /home/optmv_sci2_user01/
1347 cd /home/optmv_sci2_user01/
1348 ls
1349 mv hzs/* .
1350 sudo mv hzs/* .
1351 ls
1352 rm -rf hzs/
1353 ls -lh
1354 rm -rf hzs/
1355 sudo rm -rf hzs/
1356 ls -lh
1357 mkdir bakup
1358 sudo mkdir bakup
1359 sudo mv ar0235raw图/ bakup/
1360 mv I* bakup/
1361 ls
1362 sudo mv I* bakup/
1363 ls
1364 mv raw图/ bakup/
1365 sudo mv raw图/ bakup/
1366 ip addr
1367 cat /etc/passwd
1368 sudo passwd -S optmv_sci2_user01
1369 sudo passwd optmv_sci2_user01
1370 sudo smbpasswd optmv_sci2_user01
1371 pwd
1372 ip addr
1373 cd ~
1374 ls -lh
1375 cd /home/
1376 ls
1377 sudo smbpasswd optmv_sci2_user01
1378 ls
1379 who
1380 cat /etc/fstab
1381 sudo vim /etc/fstab
1382 sync
1383 history |grep mount
1384 sudo umount -f /home/optmv_sci2_user01/
1385 sudo umount -f /home/optmv_sci2_user01
1386 sudo mount -f /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1387 sudo systemctl daemon-reload
1388 sudo mount -f /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1389 sudo mount /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1390 ls -lh
1391 pwd
1392 ls -l /home/
1393 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1394 ls -l /home/
1395 sudo vim /etc/samba/smb.conf
1396 ls
1397 pwd
1398 cd ~
1399 ls
1400 cp -rf /etc/samba/smb.conf Bakup/ --parent
1401 sudo cp -rf /etc/samba/smb.conf Bakup/ --parent
1402 sudo vim /etc/samba/smb.conf
1403 sudo systemctl restart smbd.service
1404 sudo systemctl restart nmbd.service
1405 ls
1406 cd Bakup/
1407 ls
1408 history 200 > history1.txt
1409 vim history1.txt
1410 ls
1411 who
1412 ls -l /home/
1413 sudo chmod 755 /home/optmv_sci2_user01/
1414 ls -lh
1415 ls -lh /home/
1416 id fj
1417 who |grep fj
1418 vim history1.txt
1419 clear
1420 ls /home/lqs/
1421 ls
1422 cd /home/
1423 ls
1424 cd lqs/
1425 ls
1426 cd tmp/
1427 ls
1428 cd ..
1429 rm -rf tmp/
1430 sudo rm -rf tmp/
1431 clear
1432 cd ~
1433 ls
1434 pwd
1435 vim Bakup/history1.txt
1436 mkdir -p /home/optmv_sci2_user02
1437 sudo mkdir -p /home/optmv_sci2_user02
1438 ls -lh
1439 ls -lh /home/
1440 rm -rf /home/lqs/
1441 sudo rm -rf /home/lqs/
1442 who |grep lqs
1443 sudo umount /home/lqs
1444 sudo umount -f /home/lqs
1445 sudo lsof /home/lqs/
1446 pkill -9 -u lqs
1447 sudo umount -f /home/lqs
1448 sudo fuser -km /home/lqs/
1449 sudo umount -f /home/lqs
1450 ls
1451 ls /home/
1452 sudo vim /etc/fstab
1453 sync
1454 sudo vim /etc/samba/smb.conf
1455 sync
1456 cat /etc/fstab
1457 ls -l /home/
1458 sudo chown -R optmv_sci2_user012:optmv_sci2_user02 /home/optmv_sci2_user02/
1459 sudo groupadd optmv_sci2_user02
1460 sudo usermod -g optmv_sci2_user02 optmv_sci2_user02
1461 id optmv_sci2_user02
1462 sudo chown -R optmv_sci2_user012:optmv_sci2_user02 /home/optmv_sci2_user02/
1463 sudo umount /home/lqs
1464 sudo mount -f /dev/mapper/ubuntu--vg-lqs--lv /home/optmv_sci2_user02/
1465 sudo systemctl daemon-reload
1466 sudo mount -f /dev/mapper/ubuntu--vg-lqs--lv /home/optmv_sci2_user02/
1467 sudo chown -R optmv_sci2_user012:optmv_sci2_user02 /home/optmv_sci2_user02/
1468 sudo chown -R optmv_sci2_user02:optmv_sci2_user02 /home/optmv_sci2_user02/
1469 getent group optmv_sci2_user02
1470 sudo usermod -g optmv_sci2_user02 optmv_sci2_user02
1471 sudo useradd -m -d /home/optmv_sci2_user02 -s /bin/bash optmv_sci2_user02
1472 sudo passwd optmv_sci2_user02
1473 sudo useradd -m -d -g /home/optmv_sci2_user02 -s /bin/bash optmv_sci2_user02
1474 sudo useradd optmv_sci2_user02
1475 sudo useradd -g optmv_sci2_user02
1476 sudo useradd -m -d /home/optmv_sci2_user02 -s /bin/bash -g optmv_sci2_user02 optmv_sci2_user02
1477 sudo passwd optmv_sci2_user02
1478 sudo smbpasswd optmv_sci2_user02
1479 ls
1480 pwd
1481 ls
1482 who
1483 ip addr
1484 cat /etc/fstab
1485 sudo chown -R optmv_sci2_user02:optmv_sci2_user02 /home/optmv_sci2_user02/
1486 ls -l /home/
1487 sudo chmod 755 /home/optmv_sci2_user02/
1488 ls -lh
1489 ls -lh /home/
1490 sudo smbpasswd optmv_sci2_user02
1491 sudo smbpasswd -a optmv_sci2_user02
1492 ls -lh
1493 who
1494 cd Bakup/
1495 ls
1496 histroy 200 > history_user02.txt
1497 history 200 > history_user02.txt
~
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
1298 ls -l /home/
1299 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01
1300 cat /etc/fstab
1301 sudo pvs
1302 fdisk
1303 fdisk -lh
1304 fdisk -L
1305 lsblk
1306 sudo fdisk -l /dev/sdb
1307 sudo umount -f /home/hzs
1308 sudo pkill -9 -u hzs
1309 sudo fuser -km /home/hzs/
1310 sudo umount -f /home/hzs
1311 sudo lsof /home/hzs/
1312 sudo mount -f /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1313 df -h |grep optmv_sci
1314 mount |grep opt_sci
1315 ls -ls /home/optmv_sci2_user01/
1316 grep optmv_sci2_user01 /etc/passwd
1317 ls -lh
1318 ls -lh /home/
1319 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1320 sudo chmod 755 /home/optmv_sci2_user01/
1321 ls -lh
1322 ls -lh /home/
1323 rm -rf /home/hzs/
1324 sudo rm -rf /home/hzs/
1325 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1326 ls -lh
1327 ls -lh /home/
1328 sudo umount -l /home/hz
1329 ls -lh
1330 ls -lh /home/
1331 df -h /home/optmv_sci2_user01/
1332 sudo adduser optmv_sci2_user01
1333 sudo smbpasswd -a optmv_sci2_user01
1334 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1335 ls -l /home/
1336 id optmv_sci2_user01
1337 sudo groupadd optmv_sci2_user01
1338 sudo usermod -g optmv_sci2_user01 optmv_sci2_user01
1339 id optmv_sci2_user01
1340 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1341 how
1342 who
1343 ls -lh
1344 ls -lh /home/
1345 ls -l /home/optmv
1346 ls -l /home/optmv_sci2_user01/
1347 cd /home/optmv_sci2_user01/
1348 ls
1349 mv hzs/* .
1350 sudo mv hzs/* .
1351 ls
1352 rm -rf hzs/
1353 ls -lh
1354 rm -rf hzs/
1355 sudo rm -rf hzs/
1356 ls -lh
1357 mkdir bakup
1358 sudo mkdir bakup
1359 sudo mv ar0235raw图/ bakup/
1360 mv I* bakup/
1361 ls
1362 sudo mv I* bakup/
1363 ls
1364 mv raw图/ bakup/
1365 sudo mv raw图/ bakup/
1366 ip addr
1367 cat /etc/passwd
1368 sudo passwd -S optmv_sci2_user01
1369 sudo passwd optmv_sci2_user01
1370 sudo smbpasswd optmv_sci2_user01
1371 pwd
1372 ip addr
1373 cd ~
1374 ls -lh
1375 cd /home/
1376 ls
1377 sudo smbpasswd optmv_sci2_user01
1378 ls
1379 who
1380 cat /etc/fstab
1381 sudo vim /etc/fstab
1382 sync
1383 history |grep mount
1384 sudo umount -f /home/optmv_sci2_user01/
1385 sudo umount -f /home/optmv_sci2_user01
1386 sudo mount -f /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1387 sudo systemctl daemon-reload
1388 sudo mount -f /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1389 sudo mount /dev/mapper/ubuntu--vg-hzs--lv /home/optmv_sci2_user01/
1390 ls -lh
1391 pwd
1392 ls -l /home/
1393 sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01/
1394 ls -l /home/
1395 sudo vim /etc/samba/smb.conf
1396 ls
1397 pwd
1398 cd ~
1399 ls
1400 cp -rf /etc/samba/smb.conf Bakup/ --parent
1401 sudo cp -rf /etc/samba/smb.conf Bakup/ --parent
1402 sudo vim /etc/samba/smb.conf
1403 sudo systemctl restart smbd.service
1404 sudo systemctl restart nmbd.service
1405 ls
1406 cd Bakup/
1407 ls
1408 history 200 > history1.txt
fj → optmv_sci2_user01
详细说明如何逐个用户 执行 usermod 命令进行重命名。这样更可控,也便于排查问题。
单个用户重命名步骤(以 fj → optmv_sci2_user01 为例)
1. 准备工作
bash
# 1.1 检查用户 fj 是否存在
id fj
# 输出示例:uid=1002(fj) gid=1002(fj) groups=1002(fj)
# 1.2 检查用户 fj 是否在线
who | grep fj
# 或查看所有登录用户
w
# 1.3 如果在线,先踢出用户
sudo pkill -u fj
# 或强制杀死所有该用户进程
sudo pkill -9 -u fj
2. 备份关键文件
bash
# 备份系统文件(非常重要!)
sudo cp /etc/passwd /etc/passwd.backup.$(date +%Y%m%d_%H%M%S)
sudo cp /etc/shadow /etc/shadow.backup.$(date +%Y%m%d_%H%M%S)
sudo cp /etc/group /etc/group.backup.$(date +%Y%m%d_%H%M%S)
sudo cp /etc/gshadow /etc/gshadow.backup.$(date +%Y%m%d_%H%M%S)
# 验证备份
ls -la /etc/*.backup.*
3. 执行重命名(3种方法)
方法一:分步执行(最安全,推荐)
bash
# 步骤1: 修改用户名(用户名从 fj 改为 optmv_sci2_user01)
sudo usermod -l optmv_sci2_user01 fj
# 步骤2: 修改家目录路径并移动家目录
sudo usermod -d /home/optmv_sci2_user01 -m optmv_sci2_user01
# 步骤3: 重命名用户组(如果用户组名与旧用户名相同)
sudo groupmod -n optmv_sci2_user01 fj
# 如果提示 group 'fj' does not exist,说明没有独立组,跳过此步
方法二:一行命令执行
bash
# 先改用户名和家目录,再改组名(分两行)
sudo usermod -l optmv_sci2_user01 -d /home/optmv_sci2_user01 -m fj && \
sudo groupmod -n optmv_sci2_user01 fj
方法三:使用脚本辅助(带错误检查)
bash
#!/bin/bash
# single_user_rename.sh - 单个用户重命名脚本
OLD_USER="fj"
NEW_USER="optmv_sci2_user01"
echo "=== 开始重命名用户: $OLD_USER -> $NEW_USER ==="
# 1. 检查旧用户是否存在
if ! id "$OLD_USER" &>/dev/null; then
echo "✗ 错误:用户 $OLD_USER 不存在"
exit 1
fi
# 2. 检查新用户是否已存在
if id "$NEW_USER" &>/dev/null; then
echo "✗ 错误:用户 $NEW_USER 已存在"
exit 1
fi
# 3. 检查用户是否在线
if who | grep -q "$OLD_USER"; then
echo "⚠ 警告:用户 $OLD_USER 当前在线"
read -p "是否继续?(y/n): " confirm
if [[ "$confirm" != "y" ]]; then
echo "操作已取消"
exit 0
fi
fi
# 4. 执行重命名
echo "→ 修改用户名..."
sudo usermod -l "$NEW_USER" "$OLD_USER"
if [ $? -ne 0 ]; then
echo "✗ 修改用户名失败"
exit 1
fi
echo "→ 修改家目录..."
sudo usermod -d "/home/$NEW_USER" -m "$NEW_USER"
if [ $? -ne 0 ]; then
echo "✗ 修改家目录失败"
exit 1
fi
# 5. 重命名用户组(如果存在)
if getent group "$OLD_USER" &>/dev/null; then
echo "→ 重命名用户组..."
sudo groupmod -n "$NEW_USER" "$OLD_USER"
if [ $? -ne 0 ]; then
echo "✗ 重命名组失败"
exit 1
fi
else
echo "ℹ 用户组 $OLD_USER 不存在,跳过组重命名"
fi
echo "✓ 用户重命名成功!"
echo ""
echo "验证结果:"
id "$NEW_USER"
ls -ld "/home/$NEW_USER"
4. 验证重命名结果
bash
# 4.1 检查用户信息
id optmv_sci2_user01
# 应该显示:uid=1002(optmv_sci2_user01) gid=1002(optmv_sci2_user01) ...
# 4.2 检查家目录
ls -la /home/optmv_sci2_user01/
# 确认文件所有权已更新
# 4.3 检查 /etc/passwd
grep optmv_sci2_user01 /etc/passwd
# 输出:optmv_sci2_user01:x:1002:1002::/home/optmv_sci2_user01:/bin/bash
# 4.4 检查 /etc/group
grep optmv_sci2_user01 /etc/group
# 输出:optmv_sci2_user01:x:1002:
# 4.5 测试登录(以新用户名)
su - optmv_sci2_user01
whoami
exit
5. 其他两个用户的重命名命令
hzs → optmv_sci2_user02
bash
# 备份(如还未备份)
sudo cp /etc/passwd /etc/passwd.backup.$(date +%Y%m%d_%H%M%S)
# 执行重命名
sudo usermod -l optmv_sci2_user02 hzs
sudo usermod -d /home/optmv_sci2_user02 -m optmv_sci2_user02
sudo groupmod -n optmv_sci2_user02 hzs 2>/dev/null || echo "组不存在,跳过"
# 验证
id optmv_sci2_user02
ls -ld /home/optmv_sci2_user02
lqs → optmv_sci2_user03
bash
# 执行重命名
sudo usermod -l optmv_sci2_user03 lqs
sudo usermod -d /home/optmv_sci2_user03 -m optmv_sci2_user03
sudo groupmod -n optmv_sci2_user03 lqs 2>/dev/null || echo "组不存在,跳过"
# 验证
id optmv_sci2_user03
ls -ld /home/optmv_sci2_user03
6. 常用 usermod 参数说明
| 参数 | 说明 | 示例 |
|---|---|---|
-l NEW_LOGIN |
修改用户名 | usermod -l newname oldname |
-d NEW_HOME |
修改家目录路径 | usermod -d /home/newname username |
-m |
移动家目录内容到新位置(必须配合 -d) |
usermod -d /home/newname -m username |
-g GROUP |
修改主组 | usermod -g newgroup username |
-G GROUPS |
修改附加组 | usermod -G group1,group2 username |
-s SHELL |
修改登录 Shell | usermod -s /bin/bash username |
-L |
锁定用户 | usermod -L username |
-U |
解锁用户 | usermod -U username |
7. 可能出现的问题及解决方案
问题1:用户正在运行进程
bash
# 查看用户进程
ps -u fj
# 强制结束所有进程
sudo pkill -u fj
sudo pkill -9 -u fj
# 或优雅结束
sudo pkill -TERM -u fj
sleep 2
sudo pkill -KILL -u fj
问题2:家目录权限问题
bash
# 修复家目录权限
sudo chown -R optmv_sci2_user01:optmv_sci2_user01 /home/optmv_sci2_user01
sudo chmod 755 /home/optmv_sci2_user01
问题3:SELinux 上下文问题(如果启用)
bash
# 修复 SELinux 上下文
sudo restorecon -R /home/optmv_sci2_user01
问题4:sudo 权限丢失
bash
# 如果用户有 sudo 权限,需要更新 /etc/sudoers
sudo visudo
# 将 fj ALL=(ALL) ALL 改为 optmv_sci2_user01 ALL=(ALL) ALL
# 或使用命令替换
sudo sed -i 's/\bfj\b/optmv_sci2_user01/g' /etc/sudoers
8. 完整的一键执行三个用户
bash
#!/bin/bash
# rename_all_users.sh
echo "开始批量重命名..."
# fj -> optmv_sci2_user01
echo "处理 1/3: fj -> optmv_sci2_user01"
sudo usermod -l optmv_sci2_user01 fj 2>/dev/null && \
sudo usermod -d /home/optmv_sci2_user01 -m optmv_sci2_user01 && \
sudo groupmod -n optmv_sci2_user01 fj 2>/dev/null && \
echo "✓ fj 重命名成功" || echo "✗ fj 重命名失败"
# hzs -> optmv_sci2_user02
echo "处理 2/3: hzs -> optmv_sci2_user02"
sudo usermod -l optmv_sci2_user02 hzs 2>/dev/null && \
sudo usermod -d /home/optmv_sci2_user02 -m optmv_sci2_user02 && \
sudo groupmod -n optmv_sci2_user02 hzs 2>/dev/null && \
echo "✓ hzs 重命名成功" || echo "✗ hzs 重命名失败"
# lqs -> optmv_sci2_user03
echo "处理 3/3: lqs -> optmv_sci2_user03"
sudo usermod -l optmv_sci2_user03 lqs 2>/dev/null && \
sudo usermod -d /home/optmv_sci2_user03 -m optmv_sci2_user03 && \
sudo groupmod -n optmv_sci2_user03 lqs 2>/dev/null && \
echo "✓ lqs 重命名成功" || echo "✗ lqs 重命名失败"
echo ""
echo "最终结果:"
ls -la /home/ | grep ^d | awk '{print $3, $9}'
9. 安全建议
bash
# 1. 在测试环境先验证
# 2. 每个用户重命名后立即验证
# 3. 保持 root 会话打开(不要关闭,防止失去权限)
# 4. 如果 SSH 登录,先保持两个连接
# 5. 记录所有操作日志
# 记录操作日志
script rename_$(date +%Y%m%d_%H%M%S).log
# 执行命令...
exit # 退出日志记录
10. 快速命令清单(可直接复制执行)
bash
# 重命名 fj
sudo usermod -l optmv_sci2_user01 fj && \
sudo usermod -d /home/optmv_sci2_user01 -m optmv_sci2_user01 && \
sudo groupmod -n optmv_sci2_user01 fj 2>/dev/null
# 重命名 hzs
sudo usermod -l optmv_sci2_user02 hzs && \
sudo usermod -d /home/optmv_sci2_user02 -m optmv_sci2_user02 && \
sudo groupmod -n optmv_sci2_user02 hzs 2>/dev/null
# 重命名 lqs
sudo usermod -l optmv_sci2_user03 lqs && \
sudo usermod -d /home/optmv_sci2_user03 -m optmv_sci2_user03 && \
sudo groupmod -n optmv_sci2_user03 lqs 2>/dev/null
# 验证所有用户
for user in optmv_sci2_user01 optmv_sci2_user02 optmv_sci2_user03; do
echo "=== $user ==="
id $user
ls -ld /home/$user
echo
done
这样逐个执行,每一步都可以检查结果,出现问题也容易定位和回滚。建议在测试环境先试一遍!