-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux notes
177 lines (127 loc) · 5.13 KB
/
linux notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/var/log/ (location of log files)
$USER (USER envrioment variable)
rm -r (remove directory and subs recursivley ad f to not promt)
mv (move\rename a file)
sudo adduser user --encrypt-home
chmod 1777 (make directory with full access for your own files not others)
chown newUser file
chown :newGroup filels
awk -F":" '{ print "username: " $1 "\t\tuid:" $3 }' /etc/passwd
(list all users in system)
service ssh restart (restart ssh)
usermod -a -G group user (add group to particlar user, the -a appends)
groups user (show the groups the user is in)
sudo netstat -tanp (look for user sessions)
sudo kill -15 <process> (kill the ssh process)
vim commands:
v (start highlighting)
d (cut)
P (paste)
using screen:
Ctrl a d (detach)
screen -ls (list screens)
screen -r [particularSCreen] (reatttach a detached screen)
upstart log directory:
/var/log/upstart/your-service-name.log.
exec start-stop-daemon --start --chuid gandalf --chdir /home/gandalf/server/ --exec /home/gandalf/server/startServer.sh
start-stop-daemon --start --chuid gandalf --exec /home/gandalf/server/startServer.sh
cd $ echo $PATH
/bin (common ternminal commands)
/boot (start up stuff, kernel and boot loader config files)
/dev (all device files, refer to actual devies)
/home (for users home directories)
/media (mount point for external media devices)
/mnt (also mount point but more for things lik network drives)
/opt (stores additonal software not handled by pakage managers)
/proc (virtual filesystem, mechanism for kenrel to send info to processes)
/root (super users home directory for when home is not available on boot)
/sbin (contains super user commands)
/srv (can contain data directories of services such as http)
/tmp (place for temporary files)
/usr (contains user utilites and replicates some root dir structures)
/var (for variable data that changes rapidly such as logs)
/lost+found (place where system puts things like corrupted files)
/run (?? something to do with running processes?)
mail -s "The subject goes here" jdoe
(send mail to another useremust have mailutils installed)
mail (check mail)
sudo ufw enable (enable firewall)
sudo ufw allow <port>
//add /tcp to make it exclusive to tcp
sudo ufw remove <rule> // remove a rule
//github configuration
git config --global user.name "Your Name"
git config --global user.email [email protected]
//getting updates
sudo apt-get update # Fetches the list of available updates
sudo apt-get dist-upgrade # Installs updates
//mongodb important dirs and useful stuff
/var/log/mongodbd
/var/lib/mongodb (current location of dbs)
ps -ef | grep mongo
..repair bad mongo shutdown..
Do this...
sudo rm /var/log/mongodbd/mongod.lock
Then restart....
To be more legit try this before you restart...
sudo mongod --dbpath /var/log/mongodbd --repair
//shutdown the system
sudo shutdown -h now
//changing evnviroment varialbes
export ENV_VAR="something"
//checking them
printenv ENV_VAR
//my scripts
usr/local/bin
//a way to set up cron jobs
crontab -e
//view a log file in real time
tail -f /path/to/logfile
//eviroment variables for specific user
.bash_profile or .bashrc
also .bashrc can be used kind of like an autoexec when you start a new terminal
//mount local windows share
sudo mount -t cifs -o user=toby,uid=gandalf,gid=devs //192.168.1.149/Shared /mnt/winShare
//ssh and google authenticator configs
sudo apt-get install libpam-google-authenticator
google-authenticator (set up auth key)
/etc/pam.d/sshd
auth required pam_google_authenticator.so (add at bottom)
/etc/ssh/sshd_config
ChallengeResponseAuthentication yes (entry exist just change to yes)
sudo service ssh restart
//start a app on a remote desktop through ssh
DISPLAY=:0.0 [appToStart] &
//get server key fingerprint
ssh-keygen -lf ssh_host_rsa_key.pub
//and if it doesn't display how you need it try this
awk '{print $2}' ssh_host_rsa_key.pub | base64 -d | sha256sum -b | awk '{print $1}' | xxd -r -p | base64
//run something on reboot for a user
//using crontab, can be used for forever script
crontab -u user -e
add this to the file:
@reboot /usr/local/bin/script
//change colors in console
vim ~/.bashrc
LS_COLORS=$LS_COLORS:'di=0;35:' ; export LS_COLORS
//....see size of current directory
du -sh
..........mount a remote folder with sshfs...................
sudo sshfs -o allow_other,IdentityFile=[path_to_ssh_key] [email protected]:[path_to_remote_folder] [path_to_local_folder]
.......how to get the evn of a process....
ps -ef | grep [thing-you-want]
cd /proc/[process-id]
sudo cat eviron
......find process bound to port.....
lsof -i :port
//.....vim......
//when you forget to sudo
:w !sudo tee %
//get to bottome of page
G$
//.....replace something across a repo or a dir in a repo
git grep -lz .js | xargs -0 sed -i '' -e 's/\.js/\.jsx/g'
//......replace extensions recursively in a dir
find . -name '*.js' -exec sh -c 'mv "$0" "${0%.js}.jsx"' {} \;
git grep -lz .jsxson | xargs -0 sed -i '' -e 's/\.jsxson/\.json/g'
find . -name '*.csm' -exec sh -c 'mv "$0" "${0%.csm}.css"' {} \;