在调用system命令读写硬盘序列号的过程中遇到问题,报错如下:

sudo: no tty present and no askpass program

发现此问题是由于帐号并没有开启免密码导致的 。

查找资料,解决方法如下:

方法一:

sudo isudo

然后在最末尾添加:

username ALL = NOPASSWD: /fullpath/to/command,/fullpath/to/othercommand

eg:
john ALL = NOPASSWD: /sbin/poweroff,/sbin/start,sbin/stop

会允许用户John在进行poweroff,start,stop的时候不需要密码。这里我使用了最简单的方式,如下:

john ALL = NOPASSWD: ALL

添加完成以后就可以无须密码进行sudo操作了。(亲测可用

方法二:

1    打开sudoers

vi /etc/sudoers

2    添加免密码

john ALL = NOPASSWD: ALL

读取硬盘序列号的方法:

if(system("sudo hdparm -I /dev/sda | grep Serial >> tmpGenuine.txt")>=)
{
QFile *tmpFile = new QFile("tmpGenuine.txt");//临时存放文件
if(tmpFile->open(QIODevice::ReadOnly|QIODevice::Text))
{
while(!tmpFile->atEnd())
{
QString tmpLine;
tmpLine = tmpFile->readLine();
tmpLine.indexOf(rx2);
genuineNum += rx2.cap();
}
qDebug()<<"genuineNum:"<<genuineNum;
}
tmpFile->close();
}
else
{
qDebug()<<"can not get the Serial Num";
return ;
}

How to fix 'sudo: no tty present and no askpass program'以及硬盘序列号的读写的更多相关文章

  1. sudo: no tty present and no askpass program specified(转)

    sudo: no tty present and no askpass program specified 2012-11-30 09:30 5040人阅读 评论(1) 收藏 举报 修改sudo配置文 ...

  2. 错误提示sudo: no tty present and no askpass program specified Sorry, try again.

    php调用shell脚本的svnup.php文件内容: <?set_time_limit(0);//$output = array();$ret = 0;exec("/usr/bin/ ...

  3. sudo: no tty present and no askpass program specified

    sudo: no tty present and no askpass program specified | 学步园 https://www.xuebuyuan.com/2157339.html 通 ...

  4. Jenkins服务使用 宿主机的docker、docker-compose (Jenkins 执行sudo命令时出现“sudo: no tty present and no askpass program specified”,以及 docker-compose command not found解决办法)

    若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11681474.html 原因: 本人最近正在尝试CI/CD,所以就使用了 Jen ...

  5. sudo: 没有终端存在,且未指定 askpass 程序

    问题:sudo: 没有终端存在,且未指定 askpass 程序 解决: sudo visudo 增加如下一行: neutron    ALL=(ALL)    NOPASSWD:ALL

  6. Fix network adapter not present problem in cloned CentOS

    (You can find a lot of articles on this from the internet. I just put it here for my own record.) It ...

  7. How to execute sudo command in remote host via SSH

    Question: I have an interactive shell script, that at one place needs to ssh to another machine (Ubu ...

  8. sudo问题汇总

    1. 注释Defaults requiretty Defaults requiretty修改为 #Defaults requiretty, 表示不需要控制终端. 否则会出现sudo: sorry, y ...

  9. Jenkins执行sudo权限的设置

    Jenkins系统中添加执行脚本的时候,有一些命令是需要sudo权限和来执行的,可以在root权限下添加一下Jenkins账号的权限 1.添加不需要密码可sudo执行指定命令的权限 cd /etc c ...

随机推荐

  1. Arduino 3G shield using SoftwareSerial to control

    On the 3G shield, by default the power pin is on D8 and reset pin is on D9. Make it HIGH then it wor ...

  2. 为什么MD5不能解密

    MD5加密原理是散列算法,也称之为hash算法. 具体的算法很多种,我也不是很懂,写得太专业了,我们只能理解一些简单的.简单才能让人记得住. 举例说明,10除以3余数是1,4除以3的余数也是1,反过来 ...

  3. Hadoop 统计文件中某个单词出现的次数

    如文件word.txt内容如下: what is you name? my name is zhang san. 要求统计word.txt中出现“is”的次数? 代码如下: PerWordMapper ...

  4. 登录验证全局控制的几种方式(session)

    在登陆验证或者其他需要用到session全局变量的时候,归结起来,主要有以下三种较方便的实现方式.(其中个人较喜欢使用第一种实现方法) 一,在一个公共类里创建一个公共方法,然后需要验证的页面都调用这个 ...

  5. Eclipse相关集锦

    开场白,之前的个人博客写过很多细小的Eclipse的东西,这里将搬过来,作为整体一篇. 1.Eclipse提示失效 解决:window->Preferences->Java->Edi ...

  6. SVN使用教程之-分支/标记 合并 subeclipse

    首先说下为什么我们需要用到分支-合并.比如项目demo下有两个小组,svn下有一个trunk版.由于客户需求突然变化,导致项目需要做较大改动,此时项目组决定由小组1继续完成原来正进行到一半的工作[某个 ...

  7. 浅谈 Linux

          1969年,美国贝尔实验室的肯-汤普森在DEC PDP-7机器上开发出了UNIX系统.      1971年,肯-汤普森的同事丹尼斯-里奇发明了C语言:1973年,UNIX系统的绝大部分源 ...

  8. ubuntu16 网络设置

    打开Ubuntu的终端,输入:sudo gedit /etc/network/interfaces表示使用gedit编辑器打开interfaces文件. 在打开的文件中,若有内容,先全部删除.然后输入 ...

  9. Docker集群实验环境布署--swarm【6 配置上层Nginx代理,让任意Docker client访问得到高可用的管理API】

    10.40.42.10上,也就是对应的VRRP中的10.40.42.1和2上,配置nginx tcp代理   # cat 4000_manager.venic.com_10.40.100.141-14 ...

  10. RFC Transactional RFC (tRFC) queue RFC(qRFC) 概念

    Transactional RFC When using transactional RFC (tRFC), the called function module is executed exactl ...