在调用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. 下载centos6.4

    下载centos6.4 (原创)LAMP教程3-下载centos6.4 今天我要给大家讲的是安装CentOS-6.4-x86_64,是的没有错,就是64位的,因为我的机子是4G的内存,安装64位的ce ...

  2. java动态加载配置文件

    最近项目中需要做定时任务,即定时数据库的备份.定时时间用户可以在界面中配置,要求配置修改好立即生效. 想不到什么好办法.下面是一种实现思路 把用户配置的时间存到properties配置文件中,定时任务 ...

  3. CF 322B Ciel and Flowers 贪心水题

    B. Ciel and Flowers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Python学习入门基础教程(learning Python)--2.3.3Python函数型参详解

    本节讨论Python下函数型参的预设值问题. Python在设计函数时,可以给型参预设缺省值,当用户调用函数时可以不输入实参.如果用户不想使用缺省预设值则需要给型参一一赋值,可以给某些型参赋值或不按型 ...

  5. 两行代码实现微信小程序联系人sidebar

    话不多说,先给你们看看核心数据和结构: 一.数据: city的json array,letter的array (city的json array里的首字母是我手工放置进去的,你也可以通过for循环获得c ...

  6. Java 集合:HashSet 与 ArrayList

    Set 集合是无序不可以重复的的.List 集合是有序可以重复的. Java 集合:HashSet 与 hashCode.equals 博客里面已经说到这个问题,但是解释的还是不够清楚. 看一个小例子 ...

  7. hibernate-部分字段查询方案

    hibernate的延迟加载与本列记录不一样,延迟加载正常一般用于关联字段,或者大型字段使用. 本列的情况主要用于,某一张表有几十甚至上百个字段,例如财务报表等.但是在使用某些场景是却大多只是用其10 ...

  8. Windows Form简易计算器实现(下)

    陆陆续续更新这个计算器用了一个礼拜了,今天无论如何也要把它更完.笔者有点追求完美,再者每天都有课,晚上还有作业,还有每晚都会写一些其他的博文. 上一次漏了写如何实现计算的.思路如下: 之前得到一个栈2 ...

  9. hdu1041

    #include <iostream> #include <string> using namespace std; const int SIZE = 1001; const ...

  10. Linux下产生随机密码10方法

    有特殊符号的: cat /dev/urandom | tr -dc "a-zA-Z0-9_+\~\!\@\#\$\%\^\&\*"| fold -w 16 |head -n ...