• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Archives for December 2017

Empty A File

December 21, 2017

If you work with vi, nano or any other command line editor, deleting a line is a fairly easy thing to do. If the file is too large, deleting the content line by line is not fun. There’s a better way to empty a file without deleting it. Here are several ways.

$ > filename
$ truncate -s 0 filename
$ echo "" > filename

$ > filename $ truncate -s 0 filename $ echo "" > filename

Filed Under: Linux

Sudoers

December 21, 2017

The /etc/sudoers file gives users the ability to run commands that are typically reserved for administrators. The commands require a password or no password, depending on how you set them up in the sudoers file. The sudoers file can’t be edited using any text editor. You have to use visudo.

$ visudo

$ visudo

Add groups to access sudo.

# Allow users in techgroup to run all commands
%techgroup   ALL=(ALL)   NOPASSWD: ALL
# Allow users in techgroup without a password
%techgroup   ALL=(ALL)   NOPASSWD: ALL
# Allow users in techgroup to shutdown the system
%techgroup   localhost=/sbin/shutdown -h now
#includedir /etc/sudoers.d

# Allow users in techgroup to run all commands %techgroup ALL=(ALL) NOPASSWD: ALL # Allow users in techgroup without a password %techgroup ALL=(ALL) NOPASSWD: ALL # Allow users in techgroup to shutdown the system %techgroup localhost=/sbin/shutdown -h now #includedir /etc/sudoers.d

Typically you have to add your groups in the sudoers file. Notice the last line. Sudoers will include config files found under the /etc/sudoers.d directory. In certain circumstances, there are others pieces of software such as compliance software CFEngine that writes over changes in the sudoers file. If this is the case, then you have to add your groups in a file inside the /etc/sudoers.d directory.

Filed Under: Linux Tagged With: sudoers

Cron Allow

December 21, 2017

Some Linux distributions don’t turn on cron automatically for users. To give certain users access to cron, add them to cron.allow.

Edit cron.allow.

$ sudo nano /etc/cron.allow

$ sudo nano /etc/cron.allow

Add one user per line.

johndoe

johndoe

Save and close.

Filed Under: Linux Tagged With: cron

Check DB Connection on AWS

December 3, 2017

When setting up your cloud infrastructure, you can check if your instances have access to the database by performing this command.

$ nc -zv 10.0.0.45 3306
$ nc -zv domain.com 3306
$ nc -zv endpoint.amazonaws.com 3306

$ nc -zv 10.0.0.45 3306 $ nc -zv domain.com 3306 $ nc -zv endpoint.amazonaws.com 3306

If connection has succeeded, you’ll get a message like this in Linux and MacOS …

Connection to endpoint.amazonaws.com 3306 port [tcp/mysql] succeeded!

Connection to endpoint.amazonaws.com 3306 port [tcp/mysql] succeeded!

On Windows, you can use Telnet to test your DB connection.

C:\>telnet endpoint.amazonaws.com 3306

C:\>telnet endpoint.amazonaws.com 3306

If connection has succeeded, the result is “no message.” If there’s a problem, you’ll get this ….

Connecting To endpoint.amazonaws.com...Could not open 
connection to the host, on port 3306: Connect failed

Connecting To endpoint.amazonaws.com...Could not open connection to the host, on port 3306: Connect failed

Filed Under: Linux Tagged With: connection, database, test

  • Home
  • About
  • Archives

Copyright © 2023