Contents

How to prevent the creation of .DS_Store files on network volumes

When working on network drives with Mac OS X every Mac user will by default create .DS_Store files. Those files are used by OS X to store custom attributes like icon positions. For more info on .DS_Store files read this article.

To prevent those files from being created:

  • Open up the Terminal
  • Run the following command
    defaults write com.apple.desktopservices DSDontWriteNetworkStores true
  • Restart your Mac or log out and back in.

Those .DS_Store files will now only be created on local volumes any you no longer have Windows users yelling at you about them. 😉

How to Change the Default Shell to Bash on macOS Catalina

With macOS Catalina, Apple is now using Zsh as the default shell. We love Zsh, but the trusty old Bash shell is still included with macOS, and you can quickly switch back to Bash if you prefer.

Zsh is only the default shell on newly created user accounts, so any existing accounts you have on an upgraded  Mac will still use Bash by default unless you change it. Each user account has its own default shell preference.

From the Terminal

To change a user account’s default shell on macOS, simply run the chsh -s (change shell) command in a Terminal window.

Change the default shell to Bash by running the following command:

chsh -s /bin/bash

You’ll have to enter your user account’s password. Finally, close the Terminal window and reopen it. You’ll be using Bash instead of Zsh.

Changing the default shell to Bash on macOS Catalina.

Change the default shell back to Zsh by running this command:

chsh -s /bin/zsh

Enter your password when prompted. After you close the terminal window and reopen it, you’ll be using Zsh.

Changing the default shell to Zsh on macOS Catalina.

You can see a list of included shells you can select by running the following command:

cat /etc/shells
Listing available shells in macOS Catalina's terminal.

From System Preferences

You can also change this option graphically from System Preferences if you prefer.

Head to System Preferences > Users & Groups on your Mac. Click the lock icon and enter your password. Hold the Ctrl key, click your user account’s name in the left pane, and select “Advanced Options.”

Opening Advanced Options in Users & Groups on macOS.

Click the “Login Shell” dropdown box and select “/bin/bash” to use Bash as your default shell or “/bin/zsh” to use Zsh as your default shell. Click “OK” to save your changes.

Changing the default login shell graphically in macOS Catalina.

Bash on macOS Is Still Outdated

Note that the version of Bash (Bourne Again SHell) included with macOS is still pretty outdated, however. If you run bash --version , you’ll see that Catalina includes Bash 3.2.57 when Bash 5.0 is the latest version. Newer versions are licensed under the GPLv3 license, while Apple still distributes a version licensed under GPLv2.

In contrast, the version of Zsh (Z shell) included with macOS (check with zsh --version ), is Zsh 5.7.2, which is the latest version at the time of Catalina’s release.

Viewing the versions of Bash and Zsh on macOS Catalina.

If you want the latest version of Bash, you can install it yourself via Homebrew.

How can I permanently add my SSH private key to Keychain so it is automatically available to ssh?

On OSX, the native ssh-add client has a special argument to save the private key’s passphrase in the OSX keychain, which means that your normal login will unlock it for use with ssh. On OSX Sierra and later, you also need to configure SSH to always use the keychain (see Step 2 below).

Alternatively you can use a key without a passphrase, but if you prefer the security that’s certainly acceptable with this workflow.

Step 1 – Store the key in the keychain

Just do this once:

ssh-add -K ~/.ssh/[your-private-key]

Enter your key passphrase, and you won’t be asked for it again.

(If you’re on a pre-Sierra version of OSX, you’re done, Step 2 is not required.)

Step 2 – Configure SSH to always use the keychain

It seems that OSX Sierra removed the convenient behavior of persisting your keys between logins, and the update to ssh no longer uses the keychain by default. Because of this, you will get prompted to enter the passphrase for a key after you upgrade, and again after each restart.

The solution is fairly simple, and is outlined in this github thread comment. Here’s how you set it up:

  1. Ensure you’ve completed Step 1 above to store the key in the keychain.
  2. If you haven’t already, create an ~/.ssh/config file. In other words, in the .ssh directory in your home dir, make a file called config.
  3. In that .ssh/config file, add the following lines:
    Host *
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa

    Change ~/.ssh/id_rsa to the actual filename of your private key. If you have other private keys in your ~.ssh directory, also add an IdentityFile line for each of them. For example, I have one additional line that reads IdentityFile ~/.ssh/id_ed25519 for a 2nd private key. The UseKeychain yes is the key part, which tells SSH to look in your OSX keychain for the key passphrase.
  4. That’s it! Next time you load any ssh connection, it will try the private keys you’ve specified, and it will look for their passphrase in the OSX keychain. No passphrase typing required.

Skip Mojave/Catalina Screenshot Delay

When you take a screenshot with Mojave or Catalina using Command+Shift+3, 4 or 5, you get a thumbnail of the image in the lower right corner for a few seconds.

This can be handy if you want to access the image by clicking it, without needing to find the file.

But if you’d rather not have the thumbnail, you can turn it off.

Use Command+Shift+5 and then click on the Options button that appears in the controls.

Then uncheck Show Floating Thumbnail.

DNS Servers List

EDPnet

212.71.8.10

Google Public DNS

8.8.8.8

8.8.4.4

2001:4860:4860::8888

2001:4860:4860::8844

Level3

209.244.0.3

209.244.0.4

4.2.2.1

4.2.2.2

4.2.2.3

4.2.2.4

OpenDNS

208.67.220.220

208.67.222.222

208.67.220.222

208.67.222.220

2620:0:ccc::2

2620:0:ccd::2

AlternateDNS

198.101.242.72

23.253.163.53

Quad9

9.9.9.9

SMTP Error Codes

Error codes for the digits are listed here:

  • 1: The server has accepted the command, but does not yet take action. A confirmation message is required. Currently, this is not used.
  • 2: The server has completed the task successfully.
  • 3: The server has understood the request, but requires further information to complete it.
  • 4: The server has encountered a temporary failure. If the command is repeated without any change, it might be completed. This is hardly ever used by mail servers.
  • 5: The server has encountered an error.

Errors codes for the second digit are:

  • 0: A syntax error has occurred.
  • 1: Indicates a informational reply, for example to a HELP request.
  • 2: Refers to the connection status.
  • 3 and 4 are unspecified.
  • 5: Refers to the status of the mail system as a whole and the mail server in particular.
  • 6: This digit refers to the status of the mail server.

Error codes list more specific errors as follows:

  • 211 A system status message.
  • 214 A help message for a human reader follows.
  • 220 Service ready.
  • 221 Service closing.
  • 250 Requested action taken and completed. The best message of them all.
  • 251 The recipient is not local to the server, but it will accept and forward the message.
  • 252 The recipient cannot be VRFYed, but the server accepts the message and attempts delivery.
  • 354 Start message input and end with .. This indicates that the server is ready to accept the message itself.
  • 421 The service is not available and the connection will be closed.
  • 422 The recipient has exceeded their mailbox limit. It could also be that the delivery directory on the Virtual server has exceeded its limit.
  • 431 Not enough disk space on the delivery server. Microsoft say this NDR maybe reported as out-of-memory error.
  • 432 Classic temporary problem, the Administrator has frozen the queue.
  • 441 Intermittent network connection. The server has not yet responded. Classic temporary problem. If it persists, you will also a 5.4.x status code error.
  • 442 The server started to deliver the message but then the connection was broken.
  • 446 Too many hops. Most likely, the message is looping.
  • 447 Problem with a timeout. Check receiving server connectors.
  • 449 A DNS problem. Check your smart host setting on the SMTP connector. For example, check correct SMTP format. Also, use square brackets in the IP address [197.89.1.4] You can get this same NDR error if you have been deleting routing groups.
  • 450 The requested command failed because the user’s mailbox was unavailable.
  • 451 The command has been aborted due to a server error. Not your fault.
  • 452 The command has been aborted because the server has insufficient system storage.
  • 465 Multi-language situation. Your server does not have the correct language code page installed.
  • 500 The server could not recognize the command due to a syntax error.
  • 501 A syntax error was encountered in command arguments.
  • 502 This command is not implemented.
  • 503 The server has encountered a bad sequence of commands.
  • 504 A command parameter is not implemented.
  • 51x Problem with email address.
  • 510 Often seen with contacts. Check the recipient address.
  • 511 Another problem with the recipient address. Maybe an Outlook client replied to a message while offline.
  • 512 SMTP; 550 Host unknown. An error is triggered when the host name can’t be found. For example, when trying to send an email to bob@ nonexistantdomain.com.
  • 513 Another problem with contacts. Address field maybe empty. Check the address information.
  • 514 Two objects have the same address, which confuses the categorizer.
  • 515 Destination mailbox address invalid.
  • 516 Mailbox may have moved.
  • 517 Problem with senders mail attribute, check properties sheet in ADUC.
  • 52x NDR caused by a problem with the large size of the email.
  • 521 The message is too large. Else it could be a permissions problem. Check the recipient’s mailbox.
  • 522 The recipient has exceeded their mailbox limit.
  • 523 Recipient cannot receive messages this big. Server or connector limit exceeded.
  • 524 Most likely, a distribution list or group is trying to send an email. Check where the expansion server is situated.
  • 530 Problem with MTA, maybe someone has been editing the registry to disable the MTA / Store driver.
  • 531 Mail system full.
  • 532 System not accepting network messages.
  • 533 Remote server has insufficient disk space to hold email.
  • 534 Message too big.
  • 535 Multiple Virtual Servers are using the same IP address and port. Email probably looping.
  • 540 DNS Problem. There is no DNS server that can resolve this email address.
  • 541 No answer from host.
  • 542 Bad connection.
  • 543 Routing server failure. No available route.
  • 544 Cannot find the next hop.
  • 546 Tricky looping problem, a contact has the same email address as an Active Directory user. One user is probably using an Alternate Recipient with the same email address as a contact.
  • 547 Delivery time-out. Message is taking too long to be delivered.
  • 548 Bad recipient policy.
  • 550 The requested command failed because the user’s mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons). Underlying SMTP 500 error. Our server tried ehlo, the recipient’s server did not understand and returned a 550 or 500 error.
  • 551 The recipient is not local to the server. The server then gives a forward address to try.
  • 552 The action was aborted due to exceeded storage allocation. Possibly the disk holding the operating system is full. Or could be a syntax error if you are executing SMTP from a telnet shell.
  • 553 The command was aborted because the mailbox name is invalid. Could also be More than 5,000 recipients specified.
  • 554 The transaction failed.
  • 555 Wrong protocol version.
  • 563 More than 250 attachments.
  • 571 Permissions problem. For some reason the sender is not allowed to email this account. Perhaps an anonymous user is trying to send mail to a distribution list.
  • 572 Distribution list cannot expand and so is unable to deliver its messages.
  • 573 Internal server error, IP address related.
  • 574 Extra security features not supported.
  • 575 Cryptographic failure. Try a plain message with encryption.
  • 576 Certificate problem, encryption level maybe to high.
  • 577 Message integrity problem.

Installing a data HDD above 2.2TB

Find out what the disk device is with :

sudo df -Th
sudo fdisk -l
sudo parted -l

You should look for one that’s the same size as the disk you installed and one that’s not listed in the output of df -Th.

Make a directory to mount the drive on and change its owner :

sudo mkdir /Volumes/somename && sudo chown -R damien /Volumes/somename

Partition the disk using parted, to make sure that the partition table is GPT :

sudo parted -a optimal /dev/sdX
    (parted) mklabel gpt
    (parted) unit TB
    (parted) mkpart primary 0% 100%
    (parted) quit

Format the new disk as ext4 :

sudo mkfs.ext4 -L LABEL -m 0 -T largefile /dev/sdX1

-T for type, largefile is one inode per MB
-m 0 to free up the reserved superblocks, can also be done later with :
sudo tune2fs -m 0 /dev/sdX1

Edit /etc/fstab and add the following line to the end :

/dev/sdX1 /Volumes/somename ext3 defaults 0 0

It is recommended using the device’s UUID in the fstab, so that even if the name changes when detecting hardware at boot, the disk is still correctly identified and mounted as the correct volume.

If you don’t know the UUID of the disk, you can find it with :
sudo blkid /dev/sdb1

Mount it so that it can be used :

sudo mount /Volumes/somename

Useful Linux commands

1- Save man-page as pdf

man -t awk | ps2pdf - awk.pdf

2- Duplicate installed packages from one machine to the other (RPM-based systems)

ssh root@remote.host "rpm -qa" | xargs yum -y install

3- Stamp a text line on top of the pdf pages to quickly add some remark, comment, stamp text, 
 on top of (each of) the pages of the input pdf file

echo "This text gets stamped on the top of the pdf pages." | enscript -B -f Courier-Bold16 -o- | ps2pdf - | pdftk input.pdf stamp - output output.pdf

4- Display the number of connections to a MySQL Database

Count the number of active connections to a MySQL database.
The MySQL command “show processlist” gives a list of all the active clients.
However, by using the processlist table, in the information_schema database, we can sort and count the results within MySQL.

mysql -u root -p -BNe "select host,count(host) from processlist group by host;" information_schema

5- Create a local compressed tarball from remote host directory

ssh user@host "tar -zcf - /path/to/dir" > dir.tar.gz

This improves on #9892 by compressing the directory on the remote machine so that the amount of data transferred over the network is much smaller. The command uses ssh(1) to get to a remote host, uses tar(1) to archive and compress a remote directory, prints the result to STDOUT, which is written to a local file. In other words, we are archiving and compressing a remote directory to our local box.

6- tail a log over ssh

This is also handy for taking a look at resource usage of a remote box.

ssh -t remotebox "tail -f /var/log/remote.log"

7- Print diagram of user/groups

Parses /etc/group to “dot” format and pases it to “display” (imagemagick) to show a usefull diagram of users and groups (don’t show empty groups).

awk 'BEGIN{FS=":"; print "digraph{"}{split($4, a, ","); for (i in a) printf "\"%s\" [shape=box]\n\"%s\" -> \"%s\"\n", $1, a[i], $1}END{print "}"}' /etc/group|display

8- Draw kernel module dependancy graph.

Parse `lsmod’ output and pass to `dot’ drawing utility then finally pass it to an image viewer

lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -

9- Create strong, but easy to remember password

Why remember? Generate!
Up to 48 chars, works on any unix-like system

read -s pass; echo $pass | md5sum | base64 | cut -c -16

10- Find all files larger than 500M and less than 1GB

find / -type f -size +500M -size -1G

11- Find size of directories and files in current directory

du -h -d 1

12- Limit the cpu usage of a process

This will limit the average amount of CPU it consumes.

sudo cpulimit -p pid -l 50

13- Show the difference between two dirs

diff -qr /var/some/dir1 var/some/dir2

Reset debian-sys-maint MySQL password

On Ubuntu systems there is a (system) mysql user debian-sys-main that is used by the system’s init scripts to control the mysql database, e.g. to start or stop the mysql server. The password of this user is stored (in clear text) in /etc/mysql/debian.cnf. If this password does not match the the actual password in the mysql server the mysql init scripts will fail:

# /etc/init.d/mysql restart* Stopping MySQL database server mysqld
[fail]* Starting MySQL database server mysqld
[ OK ]# /etc/init.d/mysql status/usr/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'

Moreover trying to update the mysql server will fail with an error like:

/var/cache/apt/archives/mysql-server-5.1_5.1.37-1ubuntu5.1_i386.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

To fix the problem you have to update the mysql password for the user debian-sys-main:

  1. Get the password from /etc/mysql/debian.cnf.
    The clear text password is stored twice in the file (the lines starting with
    “password =”:# Automatically generated for Debian scripts. DO NOT TOUCH!
    [client]
    host = localhost
    user = debian-sys-maint
    password = your-secret-password
    socket = /var/run/mysqld/mysqld.sock
    [mysql_upgrade]
    host = localhost
    user = debian-sys-maint
    password = your-secret-password
    socket = /var/run/mysqld/mysqld.sock
    basedir = /usr
  2. Update the password in the mysql server (you need mysql root access):
    mysql –user root –password mysql> SET PASSWORD FOR ‘debian-sys-maint’@‘localhost’ = PASSWORD(‘your-secret-password’);
  3. If an previous mysql-server system upgrade failed, just restart the upgrade.

The (debian) documentation can be found in /usr/share/doc/mysql-server-5.1/README.Debian:

[…] You may never ever delete the special mysql user “debian-sys-main”. This
user together with the credentials in /etc/mysql/debian.cnf are used by the
init scripts to stop the server as they would require knowledge of the mysql
root users password else.
So in most of the times you can fix the situation by making sure that the
debian.cnf file contains the right password, e.g. by setting a new one
(remember to do a “flush privileges” then). […]