This list will keep growing as I do and/or need other things. Mostly exists so I don’t have to search the same things again all the time. Will maybe categorize into different posts as list grows longer.
Find a word in a file (or directory) and replace it with a new one:
find path/to/file -type f -exec sed -i ‘s/string_to_replace/new_string/g’ {} \;
‘find’ has been my best friend for cases where I have no idea of what the code is doing and/or there is no documentation, but I know something somewhere is wrong. The option to execute commands to its output is great and has made my life so much easier since I started using. Usually the find/sed command noted above is used after I verify that the string I need to replace exists (unless I have absolute certainty that it is there), which can be done with:
find path/to/file -type f -exec grep -rl ‘string_to_search’ {} \
Of course, this is just a basic form of refactoring that can be done through IDEs, but working from the command line is easier and a lot of times, the only option.
Find a list of words’ occurrences in a file. Helpful for dictionary searches! The output of the search will be from the second file:
grep -wf words_to_search file_to_search
Gives all ldap users (that your user has access to, mind you) in the specified base, outputting the info from the filters:
ldapsearch -x -h ldap_server.host -D user@host -W -b ou=group,dc=base,dc=domain ***filters can be applied here with ” -s ‘(cn=*)’ cn mail sn ” ***
Generate a RSA key pair and copy the public key into the host for login:
ssh-keygen -t rsa
ssh user@host mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh user@host ‘cat >> .ssh/authorized_keys’
After this, change the permissions of .ssh to 700 and change the permissions of .ssh/authorized_keys to 640
On the host computer, ensure that the /etc/ssh/sshd_config contains the following lines, and that they are uncommented;
PubkeyAuthentication yes
RSAAuthentication yes
If in adition you want to disable password login, make uncomment and change the password option to:
PasswordAuthentication no
Restart ssh service to apply changes.
Comments
This post has no comments yet. Be the first to comment