AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[useradd](unix)

Martin Hope
mrdaemon
Asked: 2023-04-15 05:02:01 +0800 CST

useradd --prefix 选项

  • 7

如果我没记错的话,--prefix选项useradd应该允许我从我选择的目录中更改 etc 文件,但它奇怪地添加了一个额外的/.

如果有人问,我正在使用 Linux Mint 21.1 mate 64 位版本。

我执行的整个命令是这个:

useradd -R /home/user/fakeroot -P  /home/user/Desktop newuser

这是我得到的输出

useradd: /home/user/Desktop//etc/passwd.37507: No such file or directory
useradd: cannot lock /home/user/Desktop//etc/passwd; try again later.

我怎样才能摆脱那个额外的/?

useradd
  • 1 个回答
  • 43 Views
Martin Hope
Ufder
Asked: 2022-05-03 09:26:03 +0800 CST

正确使用“useradd”命令

  • 4

在 Ubuntu 20.04 上,我试图添加一个用户,但是,它一直失败。useradd我没有看到任何错误并且对一个简单的命令感到疯狂!我究竟做错了什么?

root@myhost:~# uname -a
Linux dsdb 5.4.0-109-generic #123-Ubuntu SMP Fri Apr 8 09:10:54 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

root@myhost:~# getent group oinstall
oinstall:x:1001:

root@myhost:~# getent group dba
dba:x:1002:

root@myhost:~# useradd –g oinstall –G dba –m –d /home/oracle oracle
Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
      --badnames                do not check for bad names
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account
      --btrfs-subvolume-home    use BTRFS subvolume for home directory
  -c, --comment COMMENT         GECOS field of the new account
  -d, --home-dir HOME_DIR       home directory of the new account
  -D, --defaults                print or change default useradd configuration
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -f, --inactive INACTIVE       password inactivity period of the new account
  -g, --gid GROUP               name or ID of the primary group of the new
                                account
  -G, --groups GROUPS           list of supplementary groups of the new
                                account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create the user's home directory
  -M, --no-create-home          do not create the user's home directory
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       encrypted password of the new account
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account
  -U, --user-group              create a group with the same name as the user
  -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping
      --extrausers              Use the extra users database
useradd
  • 1 个回答
  • 798 Views
Martin Hope
Axmed
Asked: 2022-04-15 05:34:47 +0800 CST

如何在其中创建一个新用户和一个txt文件?

  • 0

我需要编写一个 bash 脚本,它将 在 ~user1/tmp/中创建一个名为user1的新用户 和一个空文件 my_txt.txt。问题是终端询问新用户的密码,我不知道如何输入它su - user1

useradd
  • 1 个回答
  • 75 Views
Martin Hope
Faheem Mitha
Asked: 2022-02-10 02:21:01 +0800 CST

在没有主目录的 Debian 中创建系统用户仍然会在 /etc/passwd 中创建一个不存在的主目录条目

  • 1

我正在尝试在 Debian 中创建一个没有主目录的系统用户,以用于getmail.

即使我这样做了:

adduser --system --group --no-create-home getmail

进入的/etc/passwd是:

getmail:x:122:156::/home/getmail:/usr/sbin/nologin

即使该/home/getmail目录从未创建。为什么要提到一个从未创建过的目录?我期待在那里看到占位符/nonexistent,它出现在/etc/passwd.

为什么要/home/getmail输入条目,如果我想要/nonexistent条目,是否必须明确说明?

useradd
  • 1 个回答
  • 225 Views
Martin Hope
Ahmad Ismail
Asked: 2022-01-28 22:37:05 +0800 CST

users 命令不显示最近添加的用户

  • 0

我创建了几个用户:

sudo useradd bart
sudo useradd marge
sudo useradd lisa
sudo useradd maggie

这些用户现在存在

$ awk -F: '{ print $1}' /etc/passwd
blueray
bart
marge
lisa
maggie

但是,这些用户不会出现在users命令输出中

$ users
blueray

可能是什么原因?

users useradd
  • 1 个回答
  • 97 Views
Martin Hope
AndreaCostanzo1
Asked: 2021-11-28 02:45:04 +0800 CST

useradd 创建一个没有密码且只能通过 ssh 访问的用户

  • 0

我正在编写一个使用命令自动创建用户的脚本useradd(我需要这个而不是adduser)。

我想以只能使用 ssh 访问的方式创建它(脚本已经在授权密钥中添加了 public_key)。

useradd --system --shell /bin/bash $NEW_USER

此命令是否允许通过密码登录?如果是,我该如何禁用它?

我想要实现的目标类似于这篇文章--disable-password中useradd描述的内容:创建没有密码的用户。

linux useradd
  • 1 个回答
  • 831 Views
Martin Hope
mehov
Asked: 2020-01-03 04:49:02 +0800 CST

使用 `useradd -R` 进行 chrooting

  • 4

如果我做对了,chroot 会限制用户仅访问给定目录。看起来useradd有这个选项(Debian 10)。

# useradd --help | grep "chroot"
  -R, --root CHROOT_DIR         directory to chroot into

看起来很简单,但似乎没有人推荐它:

  • 在linux中创建一个只能访问特定文件夹的用户
  • https://www.tecmint.com/restrict-ssh-user-to-directory-using-chrooted-jail/

为什么?它是否不够便携或不够安全/可靠?

chroot useradd
  • 1 个回答
  • 3874 Views
Martin Hope
Dude
Asked: 2019-08-24 14:43:01 +0800 CST

Red Hat Enterprise Linux 中的详细用户添加

  • 3

我正在尝试将“useradd”的结果输出到日志文件,但不幸的是没有详细的选项。例如:“useradd dude”没有输出,除非用户已经存在。

我想做类似的事情: useradd -v dude > $logfile

我想我可以检查结果代码,如果 0 查询用户的 UID 和 GID 并将其写入日志文件,例如:

log=logfile
un=dude
if useradd ${un} &>> $log; then
  uu=$(getent passwd ${un} | cut -d: -f3)
  ug=$(getent passwd ${un} | cut -d: -f4)
  uh=$(getent passwd ${un} | cut -d: -f6)
  echo "User ${un} UID:${uu} GID:${ug} ${uh} successfully added." >> $log
fi 


# cat logfile
User dude UID:1000 GID:1000 /home/dude successfully added.
useradd: user 'dude' already exists

但我想知道是否有更简单的选择。

操作系统:RHEL 7.7

解析 /var/log/secure 可能是另一个想法:

un=dude
useradd ${un} 2>&- &
bpid=$!
wait $bpid
ret=$?
sync
(grep "useradd\[${bpid}\]" /var/log/secure | tail -n 2) >> logfile

if [[ ${ret} -eq 0 ]]; then
  echo do whatever you need to do
else
  echo error
  exit 1
fi

# ./abc
do whatever you need to do
# ./abc
error

# cat logfile
Aug 24 03:48:07 vm7031 useradd[4929]: new group: name=dude, GID=1000
Aug 24 03:48:07 vm7031 useradd[4929]: new user: name=dude, UID=1000, GID=1000, home=/home/dude, shell=/bin/bash
Aug 24 03:48:09 vm7031 useradd[4940]: failed adding user 'dude', exit code: 9

不过似乎需要同步,否则 grep 将无法工作。不确定,似乎有点矫枉过正。

linux useradd
  • 2 个回答
  • 1252 Views
Martin Hope
ysalmon
Asked: 2019-07-03 21:17:04 +0800 CST

用首字母子目录(即 LETTERHOMES)组织 /home 的原因是什么?

  • 2

在我的家庭 Linux 上,一个名为 toto 的用户将在/home/toto.

在我高中的系统上,这样的用户将在/home/t/toto. 我知道这是由于 LETTERHOMES 在/etc/adduser.conf.

还有一个参数 GROUPHOMES,用于组织/home基于组的子目录,我可以看到这样做的兴趣。

然而,使用用户名的第一个字母对我来说似乎很奇怪,因为它使结构复杂化,没有语义/概念清晰。

人们为什么要这样做?

这与目录中子目录数量的限制有关吗?这些限制在现代系统中是否仍然适用?

我问这个是因为我希望能够向提出问题的学生证明这种并发症的合理性,或者摆脱它。

home useradd
  • 1 个回答
  • 89 Views
Martin Hope
osmak
Asked: 2019-04-10 09:23:37 +0800 CST

useradd 命令中的选项 -o 有什么用?

  • 8

-o命令选项的用途是什么useradd?这个选项有什么好的用例?

linux useradd
  • 2 个回答
  • 1937 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve