检索用户名并在Linux系统中进行一些操作的代码 [英] Code to retrieve the username and do some manipulation in linux system

查看:54
本文介绍了检索用户名并在Linux系统中进行一些操作的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于检索用户列表并进行一些操作的代码

我是Linux的新手,我需要一个摘录来

从linux中的用户系统中获取用户名,该用户名必须是输入.

我需要输入用户名,如果它在系统中列出,那么它应该显示用户名.


我得到了从系统列出现有用户的命令

否则会引发错误.

如果错过了一些东西,请告诉我.

在此先感谢您.

解决方案

只需读取文件"/etc/passwd".仅对存储在此文件中的本地主机密码有意义,而对于某些外部数据库(如LDAP)而言则没有意义.通常,要访问此文件,您需要具有管理帐户,并通过sudo使用此文件运行您的应用程序(顺便说一下,您是否了解sudo?我的意思是: ^ ]).

—SA


使用getpwnam()getpwnam_r()函数.它们的工作独立于用于存储用户信息的方法. 手册页 [ 解决方案

Just read the file "/etc/passwd". It only makes sense for the local host passwords stored in this file, not in some external database like LDAP. Normally, to get access to this file you need to have administrative account and run your application using this file via sudo (do you know about sudo, by the way? I mean: http://en.wikipedia.org/wiki/Sudo[^]).

—SA


Use the getpwnam() or getpwnam_r() functions. They work independently of the method used to store the user information. The manual page[^] has example code.


这篇关于检索用户名并在Linux系统中进行一些操作的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆