在调用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. Log in Spring

    记录日志向来是企业级应用程序必须考虑的事情.早些年,一个项目一个日志功能或模块,然后有了log4j这样的产品.不知是log4j将记录日志做到了极致,或是技术含量不高,又或是经济利益不明显,它已成为了这 ...

  2. 关于JSF国际化问题

    由于最近一个项目的MVC层框架用的是JSF,所以在摸索中遇到了不少的问题,其中有一项就是关于国际化的的问题. 小弟在网上找了很多的资料,其实无外乎内容就都那样,可不知是小弟人品太差还是由于确实技术上有 ...

  3. mapreduce框架详解

    hadoop 学习笔记:mapreduce框架详解 开始聊mapreduce,mapreduce是hadoop的计算框架,我学hadoop是从hive开始入手,再到hdfs,当我学习hdfs时候,就感 ...

  4. echarts配合循环计时器等出现的内存泄漏

    echarts是百度的一个图表插件,确实好用美观. 之前实习接触到的页面大多是下面这种调用方式 var chart=echarts.init(document.getElementById(dom)) ...

  5. Android自定义控件系列(一)—Button七十二变

    转载请注明出处:http://www.cnblogs.com/landptf/p/6290791.html 忙了一段时间,终于有时间整理整理之前所用到的一些知识,分享给大家,希望给同学们有些帮助,同时 ...

  6. unity3dWeb版文本转语音

    文本转语音 <script type="text/javascript"> function VioceSpeack(str) { var zhText = str; ...

  7. Codevs 4189 字典

    4189 字典 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 最经,skyzhong得到了一本好厉害的字典,这个字典里整整有n ...

  8. java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from 解决

    在用spark的yarn-cluster模式跑fpgrowth进行频繁项集挖掘的时候,报如下错误: ERROR yarn.ApplicationMaster: User class threw exc ...

  9. js 禁止复制粘贴全选

    // 取消右键菜单document.oncontextmenu = function(e){ var t = e || window.event; var elm = t.target || t.sr ...

  10. composer install 遇到问题 Problem 1 - phpunit/phpunit 5.7.5 requires php ^5.6 || ^7.0 -> your PHP version (5.5.3 0) does not satisfy that requirement.

    $ composer install Loading composer repositories with package information Updating dependencies (inc ...