• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Scripts

One liner scripts to ease your Linux tasks

Published: February 19, 2019 | Modified: June 24, 2020



An assorted collection of one-liner scripts that are helpful in Linux sysadmin’s day to day tasks.

One liner scripts!

In this article, I am consolidating many one-liner scripts that I used or came across which will help you to perform Linux day to day tasks. Great way to save your time in repetitive work ensuring zero human errors!

Setting up hostname in SUSE (older versions)

I always prefer hostnamectl to set hostname in systems running on newer kernels.

# echo myserver.mydomain.com > /etc/HOSTNAME
# sed --in-place 's/preserve_hostname: false/preserve_hostname: true/' /etc/cloud/cloud.cfg #For Cloud servers
# sed --in-place 's/DHCLIENT_SET_HOSTNAME="yes"/DHCLIENT_SET_HOSTNAME="no"/' /etc/sysconfig/network/dhcp
# hostname myserver

Add your hostname instead of myserver and your FQDN domain instead of mydomain.


Setting up nameservers in Linux

# echo "nameserver 10.8.14.33 #Lab nameserver1
nameserver 10.8.17.33 #Lab nameserver2
search lab.kerneltalks.com">>/etc/resolv.conf

Add your own nameserver IPs and search domain in above code.


Add FQDN in hostfile

This applies to server with single IP allocated only.

# echo "`hostname -I` `hostname`.labs.kerneltalks.com `hostname`">>/etc/hosts

Add your own domain instead of labs.kerneltalks.com


Configure sudo so that it asks user’s password when user tries to execute sudo

# sed --in-place 's/Defaults targetpw/#Defaults targetpw/' /etc/sudoers

Remove existing NTP servers and add new in /etc/ntp.conf

# sed -e '/^server/s/^/#/g' -i /etc/ntp.conf
# echo "server 10.8.14.8 #Lab NTP1
server 10.8.14.9 #Lab NTP2">>/etc/ntp.conf

Commands to enable root access in Linux server

Below is a list of the commands you can execute to enable root access on the Cloud server or AWS Linux server.

# sed --in-place 's/PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config

# sed --in-place 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
# service sshd restart
# passwd root

If you are doing it on a public cloud server make sure that you reset the root account password since cloud server spin up with key-based authentication and their root does not carry a password initially.


Test port connectivity using telnet and exit in single command

# echo 'exit' | telnet 10.10.0.1 7657
Trying 10.10.0.1...
Connected to 10.10.0.1.
Escape character is '^]'.
Connection closed by foreign host.
⇠ Previous article
How to upgrade SUSE 12 SP1 to SP3 or SP4
Next article ⇢
Script to create mount points in LVM

Related stuff:

  • Bash fork bomb: How does it work
  • How to change sender’s email id in EMS HPUX
  • Script to create mount points in LVM
  • Get list of desired LUN id from powermt output
  • cut command and its examples
  • 3 tricks to get multiple commands output in the same row
  • List WWN of online FC in HPUX server
  • Shell scripting basics: IF, FOR and WHILE loop
  • HPUX: APA configuration testing script

Filed Under: Scripts Tagged With: linux quick scripts, linux scripts, one liner scripts

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.